Platform: RK3368
OS: Android 6.0
Kernel: 3.10.0
SystemUI收到广播后可以显示或者隐藏系统界面,配合全屏应用可以做到真正全屏,且无法正常调出导航栏与状态栏。
frameworks/base/packages/SystemUI
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index 09b9e5d..ffc488c 100755 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -1061,6 +1061,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_SCREEN_ON); + filter.addAction("action.HIDE_STATUSBAR"); + filter.addAction("action.SHOW_STATUSBAR"); + filter.addAction("action.HIDE_NAVIGATIONBAR"); + filter.addAction("action.SHOW_NAVIGATIONBAR"); context.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null); IntentFilter demoFilter = new IntentFilter(); @@ -3093,6 +3097,26 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, else if (Intent.ACTION_SCREEN_ON.equals(action)) { notifyNavigationBarScreenOn(true); } + else if(action.equals("action.HIDE_STATUSBAR")) { + //Log.i(TAG, "hide statusbar"); + if (mStatusBarWindow != null) + mStatusBarWindow.setVisibility(View.GONE); + } + else if(action.equals("action.SHOW_STATUSBAR")) { + //Log.i(TAG, "show statusbar"); + if (mStatusBarWindow != null) + mStatusBarWindow.setVisibility(View.VISIBLE); + } + else if(action.equals("action.HIDE_NAVIGATIONBAR")) { + //Log.i(TAG, "hide navigationbar"); + if (mNavigationBarView != null) + mNavigationBarView.setVisibility(View.GONE); + } + else if(action.equals("action.SHOW_NAVIGATIONBAR")) { + //Log.i(TAG, "show navigationbar"); + if (mNavigationBarView != null) + mNavigationBarView.setVisibility(View.VISIBLE); + } } };
在全屏应用中使用示例:
private static final String ACTION_HIDE_STATUSBAR = "action.HIDE_STATUSBAR"; private static final String ACTION_SHOW_STATUSBAR = "action.SHOW_STATUSBAR"; private static final String ACTION_HIDE_NAVIGATIONBAR = "action.HIDE_NAVIGATIONBAR"; private static final String ACTION_SHOW_NAVIGATIONBAR = "action.SHOW_NAVIGATIONBAR"; public static void hideStatusBar(Context context, boolean hide) { Intent intent = new Intent(); intent.setPackage("com.android.systemui"); if (hide) { intent.setAction(ACTION_HIDE_STATUSBAR); } else { intent.setAction(ACTION_SHOW_STATUSBAR); } context.sendBroadcast(intent); } public static void hideNavigationBar(Context context, boolean hide) { Intent intent = new Intent(); intent.setPackage("com.android.systemui"); if (hide) { intent.setAction(ACTION_HIDE_NAVIGATIONBAR); } else { intent.setAction(ACTION_SHOW_NAVIGATIONBAR); } context.sendBroadcast(intent); }
附上应用全屏主题:
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="android:windowFullscreen">true</item> <item name="android:windowTranslucentNavigation">true</item> </style>
转载请标明出处:添加显示隐藏状态栏、导航栏广播接收
文章来源: 添加显示隐藏状态栏、导航栏广播接收