【3588】Android动态隐藏导航栏

本文介绍瑞芯微RK3566/RK3568在Android11系统下,动态屏蔽导航栏/状态栏方法。

原始问题是打开客户apk的时候导航栏不会自动隐藏,,会导致应用有一部分显示被导航栏遮住,正常的需求是打开apk之后过一段时间导航栏隐藏起来,上划再出现。

下面是直接能用的补丁:

c 复制代码
diff --git a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index f125b7d100..066a9400d5 100644
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -248,6 +248,9 @@ public class StatusBar extends SystemUI implements DemoMode,
         LifecycleOwner, BatteryController.BatteryStateChangeCallback {
     public static final boolean MULTIUSER_DEBUG = false;
 
+    private RegisterStatusBarResult mRegisterStatusBarResult;
+    static final String HIDE_NAVIGATION_BAR = "android.intent.action.HIDE_NAVIGATION_BAR";
+static final String SHOW_NAVIGATION_BAR = "android.intent.action.SHOW_NAVIGATION_BAR";
     protected static final int MSG_HIDE_RECENT_APPS = 1020;
     protected static final int MSG_PRELOAD_RECENT_APPS = 1022;
     protected static final int MSG_CANCEL_PRELOAD_RECENT_APPS = 1023;
@@ -869,6 +872,7 @@ public class StatusBar extends SystemUI implements DemoMode,
             ex.rethrowFromSystemServer();
         }
 
+        mRegisterStatusBarResult = result;
         createAndAddWindows(result);
 
         if (mWallpaperSupported) {
@@ -1288,6 +1292,8 @@ public class StatusBar extends SystemUI implements DemoMode,
         filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
         filter.addAction(Intent.ACTION_SCREEN_OFF);
         filter.addAction(DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG);
+        filter.addAction(HIDE_NAVIGATION_BAR);
+        filter.addAction(SHOW_NAVIGATION_BAR);
         mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter, null, UserHandle.ALL);
     }
 
@@ -2804,10 +2810,43 @@ public class StatusBar extends SystemUI implements DemoMode,
             }
             else if (DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG.equals(action)) {
                 mQSPanel.showDeviceMonitoringDialog();
+            } else if (HIDE_NAVIGATION_BAR.equals(action)) {
+                Log.d(TAG,"yjr1107 hideNavigation 0");
+                hideNavigation();
+            } else if (SHOW_NAVIGATION_BAR.equals(action)) {
+                Log.d(TAG,"yjr1107 displayNavigation 1");
+                displayNavigation();
             }
         }
     };
 
+    public void hideNavigation() {
+        NavigationBarView mNavigationBarView = mNavigationBarController.getDefaultNavigationBarView();
+        Log.d(TAG,"yjr1107 hideNavigation 1");
+        if (mNavigationBarView != null) {
+            Log.d(TAG,"yjr1107 hideNavigation 2");
+            mNavigationBarController.onDisplayRemoved(mDisplayId);
+        }
+	if (mPhoneStatusBarWindow != null){
+		Log.d(TAG,"yjr1107 hideNavigation 3");
+                           mPhoneStatusBarWindow.setVisibility(View.GONE);
+	}
+    }
+    public void displayNavigation() {
+        Log.d(TAG,"yjr1107 displayNavigation 1");
+        NavigationBarView mNavigationBarView = mNavigationBarController.getDefaultNavigationBarView();
+        if (mNavigationBarView == null) {
+            Log.d(TAG,"yjr1107 displayNavigation 2");
+            createNavigationBar(mRegisterStatusBarResult);
+        }
+        if (mPhoneStatusBarWindow != null){
+		Log.d(TAG,"yjr1107 displayNavigation 3");
+                     mPhoneStatusBarWindow.setVisibility(View.VISIBLE);
+		     requestNotificationUpdate("StatusBar state changed");
+            checkBarModes();
+	}
+    }
+
     private final BroadcastReceiver mDemoReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
diff --git a/frameworks/base/services/core/java/com/android/server/wm/DisplayPolicy.java b/frameworks/base/services/core/java/com/android/server/wm/DisplayPolicy.java
index 29881cc761..2e305824c9 100644
--- a/frameworks/base/services/core/java/com/android/server/wm/DisplayPolicy.java
+++ b/frameworks/base/services/core/java/com/android/server/wm/DisplayPolicy.java
@@ -16,6 +16,7 @@
 
 package com.android.server.wm;
 
+import android.util.Log;
 import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
 import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
 import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
@@ -448,6 +449,8 @@ public class DisplayPolicy {
     private static final int MSG_ENABLE_POINTER_LOCATION = 4;
     private static final int MSG_DISABLE_POINTER_LOCATION = 5;
 
+    private static final int MSG_HIDE_NAVIGATIONBAR = 30;
+    private static final int MSG_SHOW_NAVIGATIONBAR = 31;
     private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
     private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
 
@@ -480,6 +483,16 @@ public class DisplayPolicy {
                 case MSG_DISABLE_POINTER_LOCATION:
                     disablePointerLocation();
                     break;
+                case MSG_SHOW_NAVIGATIONBAR:
+                    Log.d(TAG, "yjr MSG_SHOW_NAVIGATIONBAR");
+		    Intent test1 = new Intent("android.intent.action.SHOW_NAVIGATION_BAR");
+                    mContext.sendBroadcast(test1);
+                    break;
+                case MSG_HIDE_NAVIGATIONBAR:
+		    Intent test2 = new Intent("android.intent.action.HIDE_NAVIGATION_BAR");
+                    mContext.sendBroadcast(test2);
+                    Log.d(TAG, "yjr MSG_HIDE_NAVIGATIONBAR");
+                    break;
             }
         }
     }
@@ -530,6 +543,10 @@ public class DisplayPolicy {
                             }
                             checkAltBarSwipeForTransientBars(ALT_BAR_TOP);
                         }
+                        Log.d(TAG, "yjr pwm onSwipeFromTop");
+                        mHandler.removeMessages(MSG_HIDE_NAVIGATIONBAR);
+			            mHandler.removeMessages(MSG_SHOW_NAVIGATIONBAR);
+                        mHandler.sendEmptyMessageDelayed(MSG_SHOW_NAVIGATIONBAR,200);
                     }
 
                     @Override
@@ -541,6 +558,10 @@ public class DisplayPolicy {
                             }
                             checkAltBarSwipeForTransientBars(ALT_BAR_BOTTOM);
                         }
+                        Log.d(TAG, "yjr pwm onSwipeFromBottom");
+                        mHandler.removeMessages(MSG_HIDE_NAVIGATIONBAR);
+                        mHandler.removeMessages(MSG_SHOW_NAVIGATIONBAR);
+                        mHandler.sendEmptyMessageDelayed(MSG_SHOW_NAVIGATIONBAR,200);
                     }
 
                     @Override
@@ -609,6 +630,9 @@ public class DisplayPolicy {
                         if (listener != null) {
                             listener.onTouchEnd();
                         }
+                        Log.d(TAG, "yjr pwm onUpOrCancel----------");
+                        mHandler.removeMessages(MSG_HIDE_NAVIGATIONBAR);
+                        mHandler.sendEmptyMessageDelayed(MSG_HIDE_NAVIGATIONBAR, 5000);
                     }
 
                     @Override
相关推荐
云起SAAS16 小时前
抖音小游戏源码 - 消消乐 | 含激励广告+成就系统 | 开箱即用商业级消除游戏模板
android·游戏·广告联盟·看激励广告联盟流量主·抖音小游戏源码 - 消消乐
大貔貅喝啤酒17 小时前
基于Windows下载安装Android Studio 3.3.2版本教程(2026详细图文版)
android·java·windows·android studio
程序员码歌17 小时前
OpenSpec 到 Superpowers:AI 编码从说清到做对
android·前端·人工智能
2501_9151063218 小时前
深入解析无源码iOS加固原理与方案,保护应用安全
android·安全·ios·小程序·uni-app·cocoa·iphone
黄林晴21 小时前
重磅官宣:Android UI 开发正式进入 Compose-first 时代
android·google io
Kapaseker21 小时前
搞懂变换!精通 Compose 绘制(二)
android·kotlin
美狐美颜SDK开放平台1 天前
美颜SDK开发详解:如何优化美颜SDK在低端安卓机上的性能?
android·ios·音视频·直播美颜sdk·视频美颜sdk
Gary Studio1 天前
深入MTK Android BSP:如何确定编译目标与查找项目设备树
android
casual_clover1 天前
【Android】实现状态栏背景透明,系统时间/图标直接显示在页面背景上
android·透明状态栏
blackorbird1 天前
Android Pixel 10 零点击漏洞利用链
android