功能:实现顶部状态栏和底部导航栏的显示隐藏控制
在以下文件中进行修改frameworks/basepackages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
import android.database.ContentObserver;
在makeStatusBarView()函数中添加
showStatusBar((Settings.Global.getInt(mContext.getContentResolver(),
"show_status_bar", 1) != 0));
showNavBar((Settings.Global.getInt(mContext.getContentResolver(),
"show_nav_bar", 1) != 0));
mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor("show_status_bar"), true,mShowStatusBarModeObserver);
mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor("show_nav_bar"), true,mShowNavBarModeObserver);
添加以下函数
private void showStatusBar(boolean isShow) {
Log.v(TAG, "showStatusBar = " + isShow);
if (mStatusBarWindow != null) {
mStatusBarWindow.setVisibility(isShow ? View.VISIBLE : View.GONE);
}
}
private void showNavBar(boolean isShow) {
if (mNavigationBarView != null) {
Log.i(TAG, "show nav bar =" + isShow);
mNavigationBarView.setVisibility(isShow ? View.VISIBLE : View.GONE);
}
}
private void addNavigationBarInnerLocked(){
if(mNavigationBarView == null){
createNavigationBar();
}
}
private void removeNavigationBar() {
if (mNavigationBarView == null) return;
mWindowManager.removeView(mNavigationBarView);
mNavigationBarView = null;
}
private ContentObserver mShowStatusBarModeObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
showStatusBar((Settings.Global.getInt(mContext.getContentResolver(),
"show_status_bar", 1) != 0));
}
};
private ContentObserver mShowNavBarModeObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
if(Settings.Global.getInt(mContext.getContentResolver(),"show_nav_bar", 1) != 0){
addNavigationBarInnerLocked();
}else{
removeNavigationBar();
}
}
};



