在android6.0项目中,因需要做全屏处理,故在此整理出全屏时禁止通知栏下滑的代码,希望可以帮助到也有如此困惑的人。
1.在onCreate中添加://设置全屏
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
2.在onResume()函数中添加://进入activity时,设置禁止通知栏不滑
Settings.System.putInt(this.getContentResolver(),
Settings.System.FULL_SCREEN_EXPAND_STATUSBAR, 0);
3.在onPause()函数中添加://离开activity时,恢复通知栏下滑
Settings.System.putInt(this.getContentResolver(),
Settings.System.FULL_SCREEN_EXPAND_STATUSBAR, 1);
4.在frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.javar的updateSystemUiViSiBilityLw()函数中添加://此代码我添加在tmpVisibility = updateLightStatusBarLw(tmpVisibility);后,有可能其它人的项目代码有改动,在需要此代码的请酌情添加至合适位置。
final int visibility;
if(Settings.System.getInt(mContext.getContentResolver(),
Settings.System.FULL_SCREEN_EXPAND_STATUSBAR, 1) == 0) {
visibility = tmpVisibility;
}else{
visibility = updateSystemBarsLw(win, mLastSystemUiFlags,tmpVisibility);
}
5.在frameworks/base/core/java/android/provider/Settings.java中添加://定义FULL_SCREEN_EXPAND_STATUSBAR
public static final String FULL_SCREEN_EXPAND_STATUSBAR = "full_screen_expand_statusbar";
6.在frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java中添加://与上方onPause()中意义基本相同,未深究
systemSettings.insertSettingLocked(Settings.System.FULL_SCREEN_EXPAND_STATUSBAR, "1",SettingsState.SYSTEM_PACKAGE_NAME);
说明:为保证添加了FULL_SCREEN_EXPAND_STATUSBAR不会给系统其它地方造成影响,上述6处的代码请完整添加,否则有可能引起未知错误!
转载于:https://blog.51cto.com/qiangguozky/1784409