最近有个需求: 勾选"永久隐藏工具栏"时,要求导航栏隐藏,状态栏不隐藏。
一. 源码中找到/packages/apps/Settings/src/com/android/settings/DisplaySettings.java:
可以看到勾选"永久隐藏工具栏"时发送了个广播,
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if(preference == mSystemBarHide)
{
if(mSystemBarHide.isChecked()){
Intent i = new Intent("com.cdhx.removebar");
getActivity().sendBroadcast(i);
} else {
Intent i = new Intent("com.cdhx.addbar");
getActivity().sendBroadcast(i);
}
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
二. 在/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java:
2.1.找到对应的广播动作:
else if("com.cdhx.removebar".equals(action)) {
Settings.System.putInt(mContext.getContentResolver(), Settings.System.SYSTEMBAR_HIDE,1);
mHandler.removeMessages(MSG_CHANGE_BAR_HIDE_STATUS);
mHandler.sendEmptyMessageDelayed(MSG_CHANGE_BAR_HIDE_STATUS, 400);
}
2.2.对应的更新UI消息:
case MSG_CHANGE_BAR_HIDE_STATUS:
changeBarHideStatus();
break;
找到changeBarHideStatus();
private void changeBarHideStatus()
{
boolean hide_systembar = Settings.System.getInt(mContext.getContentResolver(),Settings.System.SYSTEMBAR_HIDE,0)==1;
if(hide_systembar)
removeBar(false);
else{
addBarInside(hide_systembar);
}
}
三.找到removeBar( ):
private void removeBar(boolean needToast){
if (mBarIsAdd){
Log.d(TAG,"remove Bar");
if(mContext.getResources().getConfiguration().enableMultiWindow()){
try {
mWindowManagerService.changeTitleBar(false);
} catch (RemoteException e) {
Log.w(TAG, "Error changeTitleBar transition: " + e);
}
}
if (mNavigationBarView != null){
mWindowManager.removeViewImmediate(mNavigationBarView);
}
if (!mContext.getResources().getConfiguration().enableMultiWindow()&&mStatusBarWindow != null)
mStatusBarWindow.setVisibility(View.GONE);
if(signalCluster_win!=null)
signalCluster_win=null;
if (mNavigationBarView != null)
mNavigationBarView = null;
if(mNotificationLite != null){
mNotificationLite.closeCenter();
}
mBarIsAdd = false;
if(!isMultiChange)
Toast.makeText(mContext, mContext.getResources().getString(R.string.hidebar_msg)
, 1000).show();
}
}
可以看到如上加厚的状态栏这句。将其注释掉,即可实现勾选"永久隐藏工具栏"时,导航栏隐藏而状态栏不隐藏。