赞
踩
最近有个项目,客户要求在底部导航栏中添加一个可以隐藏整个导航栏的功能按钮,效果如下图:
具体方法如下:
1. 在frameworks/base做如下修改:
- diff --git a/packages/SystemUI/res/layout/navigation_bar.xml b/packages/SystemUI/res/layout/navigation_bar.xml
- old mode 100644
- new mode 100755
- index 5f59e781ef5e..538a0119cd09
- --- a/packages/SystemUI/res/layout/navigation_bar.xml
- +++ b/packages/SystemUI/res/layout/navigation_bar.xml
- @@ -33,4 +33,12 @@
- android:clipChildren="false"
- android:clipToPadding="false" />
-
- + <ImageView
- + android:layout_width="30dp"
- + android:layout_height="30dp"
- + android:id="@+id/navigation_hide_iv"
- + android:src="@drawable/ic_sysbar_hide"
- + android:layout_gravity="start|center_vertical"
- + android:layout_marginStart="@dimen/navigation_hide_button_start_margin" />
- +
- </com.android.systemui.navigationbar.NavigationBarView>
- diff --git a/packages/SystemUI/res/values-land/dimens.xml b/packages/SystemUI/res/values-land/dimens.xml
- old mode 100644
- new mode 100755
- index e09f7a6f0b57..6b19713923d6
- --- a/packages/SystemUI/res/values-land/dimens.xml
- +++ b/packages/SystemUI/res/values-land/dimens.xml
- @@ -60,4 +60,6 @@
-
- <dimen name="qs_panel_padding_top">@dimen/qqs_layout_margin_top</dimen>
- <dimen name="qs_panel_padding_top_combined_headers">@dimen/qs_panel_padding_top</dimen>
- +
- + <dimen name="navigation_hide_button_start_margin">40dp</dimen>
- </resources>
- diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
- old mode 100644
- new mode 100755
- index 6f1a13de60ed..40659c8542b9
- --- a/packages/SystemUI/res/values/dimens.xml
- +++ b/packages/SystemUI/res/values/dimens.xml
- @@ -1567,4 +1567,6 @@
- <dimen name="dream_overlay_status_bar_ambient_text_shadow_dx">0.5dp</dimen>
- <dimen name="dream_overlay_status_bar_ambient_text_shadow_dy">0.5dp</dimen>
- <dimen name="dream_overlay_status_bar_ambient_text_shadow_radius">2dp</dimen>
- +
- + <dimen name="navigation_hide_button_start_margin">24dp</dimen>
- </resources>
- diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
- old mode 100644
- new mode 100755
- index 3789cbb1fb65..53d3fa4855aa
- --- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
- +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
- @@ -25,6 +25,7 @@ import static com.android.systemui.shared.recents.utilities.Utilities.isTablet;
-
- import android.content.ContentResolver;
- import android.content.Context;
- +import android.content.Intent;
- import android.content.pm.ActivityInfo;
- import android.content.res.Configuration;
- import android.hardware.display.DisplayManager;
- @@ -47,6 +48,7 @@ import androidx.annotation.Nullable;
- import com.android.internal.annotations.VisibleForTesting;
- import com.android.internal.statusbar.RegisterStatusBarResult;
- import com.android.settingslib.applications.InterestingConfigChanges;
- +import com.android.systemui.R;
- import com.android.systemui.Dumpable;
- import com.android.systemui.dagger.SysUISingleton;
- import com.android.systemui.dagger.qualifiers.Main;
- @@ -63,6 +65,7 @@ import com.android.systemui.statusbar.phone.BarTransitions.TransitionMode;
- import com.android.systemui.statusbar.phone.LightBarController;
- import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
- import com.android.systemui.statusbar.policy.ConfigurationController;
- +import com.android.systemui.statusbar.phone.CentralSurfacesImpl;
- import com.android.wm.shell.back.BackAnimation;
- import com.android.wm.shell.pip.Pip;
-
- @@ -294,6 +297,8 @@ public class NavigationBarController implements
- }
- }
-
- + private int displayId;
- +
- /**
- * Adds a navigation bar on default display or an external display if the display supports
- * system decorations.
- @@ -306,7 +311,7 @@ public class NavigationBarController implements
- return;
- }
-
- - final int displayId = display.getDisplayId();
- + displayId = display.getDisplayId();
- final boolean isOnDefaultDisplay = displayId == DEFAULT_DISPLAY;
-
- // We may show TaskBar on the default display for large screen device. Don't need to create
- @@ -343,6 +348,7 @@ public class NavigationBarController implements
- result.mImeWindowVis, result.mImeBackDisposition,
- result.mShowImeSwitcher);
- }
- + context.sendBroadcast(new Intent(CentralSurfacesImpl.ACTION_HIDE_NAVIGATIONBAR));
- }
-
- @Override
- @@ -352,6 +358,13 @@ public class NavigationBarController implements
- });
- }
-
- + //edit by chain
- + public void initHideButton() {
- + NavigationBarView navigationBarView = getNavigationBarView(displayId);
- + View navigationHideIv = navigationBarView.findViewById(R.id.navigation_hide_iv);
- + navigationHideIv.setOnClickListener(v -> removeNavigationBar(displayId));
- + }
- +
- void removeNavigationBar(int displayId) {
- NavigationBar navBar = mNavigationBars.get(displayId);
- if (navBar != null) {
- @@ -368,6 +381,11 @@ public class NavigationBarController implements
- }
- }
-
- + public boolean canShowNavigationBar() {
- + NavigationBar navBar = mNavigationBars.get(displayId);
- + return navBar == null;
- + }
- +
- /** @see NavigationBar#finishBarAnimations() */
- public void finishBarAnimations(int displayId) {
- NavigationBar navBar = mNavigationBars.get(displayId);
- diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java
- old mode 100644
- new mode 100755
- index 0b63bbfec877..f78b86556d28
- --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java
- +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java
- @@ -879,6 +879,8 @@ public class CentralSurfacesImpl extends CoreStartable implements
- wiredChargingRippleController.registerCallbacks();
- }
-
- + private RegisterStatusBarResult mBarRresult;
- +
- @Override
- public void start() {
- mScreenLifecycle.addObserver(mScreenObserver);
- @@ -917,14 +919,14 @@ public class CentralSurfacesImpl extends CoreStartable implements
- mKeyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
- mWallpaperSupported = mWallpaperManager.isWallpaperSupported();
-
- - RegisterStatusBarResult result = null;
- + //RegisterStatusBarResult result = null;
- try {
- - result = mBarService.registerStatusBar(mCommandQueue);
- + mBarRresult = mBarService.registerStatusBar(mCommandQueue);
- } catch (RemoteException ex) {
- ex.rethrowFromSystemServer();
- }
-
- - createAndAddWindows(result);
- + createAndAddWindows(mBarRresult);
-
- if (mWallpaperSupported) {
- // Make sure we always have the most current wallpaper info.
- @@ -939,30 +941,30 @@ public class CentralSurfacesImpl extends CoreStartable implements
- // Set up the initial notification state. This needs to happen before CommandQueue.disable()
- setUpPresenter();
-
- - if (containsType(result.mTransientBarTypes, ITYPE_STATUS_BAR)) {
- + if (containsType(mBarRresult.mTransientBarTypes, ITYPE_STATUS_BAR)) {
- showTransientUnchecked();
- }
- - mCommandQueueCallbacks.onSystemBarAttributesChanged(mDisplayId, result.mAppearance,
- - result.mAppearanceRegions, result.mNavbarColorManagedByIme, result.mBehavior,
- - result.mRequestedVisibilities, result.mPackageName, result.mLetterboxDetails);
- + mCommandQueueCallbacks.onSystemBarAttributesChanged(mDisplayId, mBarRresult.mAppearance,
- + mBarRresult.mAppearanceRegions, mBarRresult.mNavbarColorManagedByIme, mBarRresult.mBehavior,
- + mBarRresult.mRequestedVisibilities, mBarRresult.mPackageName, mBarRresult.mLetterboxDetails);
-
- // StatusBarManagerService has a back up of IME token and it's restored here.
- - mCommandQueueCallbacks.setImeWindowStatus(mDisplayId, result.mImeToken,
- - result.mImeWindowVis, result.mImeBackDisposition, result.mShowImeSwitcher);
- + mCommandQueueCallbacks.setImeWindowStatus(mDisplayId, mBarRresult.mImeToken,
- + mBarRresult.mImeWindowVis, mBarRresult.mImeBackDisposition, mBarRresult.mShowImeSwitcher);
-
- // Set up the initial icon state
- - int numIcons = result.mIcons.size();
- + int numIcons = mBarRresult.mIcons.size();
- for (int i = 0; i < numIcons; i++) {
- - mCommandQueue.setIcon(result.mIcons.keyAt(i), result.mIcons.valueAt(i));
- + mCommandQueue.setIcon(mBarRresult.mIcons.keyAt(i), mBarRresult.mIcons.valueAt(i));
- }
-
- if (DEBUG) {
- Log.d(TAG, String.format(
- "init: icons=%d disabled=0x%08x lights=0x%08x imeButton=0x%08x",
- numIcons,
- - result.mDisabledFlags1,
- - result.mAppearance,
- - result.mImeWindowVis));
- + mBarRresult.mDisabledFlags1,
- + mBarRresult.mAppearance,
- + mBarRresult.mImeWindowVis));
- }
-
- IntentFilter internalFilter = new IntentFilter();
- @@ -1028,8 +1030,8 @@ public class CentralSurfacesImpl extends CoreStartable implements
- mAccessibilityFloatingMenuController.init();
-
- // set the initial view visibility
- - int disabledFlags1 = result.mDisabledFlags1;
- - int disabledFlags2 = result.mDisabledFlags2;
- + int disabledFlags1 = mBarRresult.mDisabledFlags1;
- + int disabledFlags2 = mBarRresult.mDisabledFlags2;
- mInitController.addPostInitTask(
- () -> setUpDisableFlags(disabledFlags1, disabledFlags2));
-
- @@ -1398,11 +1400,15 @@ public class CentralSurfacesImpl extends CoreStartable implements
- return mLifecycle;
- }
-
- + public static final String ACTION_HIDE_NAVIGATIONBAR = "action_hide_navigationbar";
- + public static final String ACTION_SHOW_NAVIGATIONBAR = "action_show_navigationbar";
- @VisibleForTesting
- protected void registerBroadcastReceiver() {
- IntentFilter filter = new IntentFilter();
- filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
- filter.addAction(Intent.ACTION_SCREEN_OFF);
- + filter.addAction(ACTION_HIDE_NAVIGATIONBAR);
- + filter.addAction(ACTION_SHOW_NAVIGATIONBAR);
- mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter, null, UserHandle.ALL);
- }
-
- @@ -2660,6 +2666,13 @@ public class CentralSurfacesImpl extends CoreStartable implements
- }
- finishBarAnimations();
- resetUserExpandedStates();
- + }else if (ACTION_HIDE_NAVIGATIONBAR.equals(action)){
- + mNavigationBarController.initHideButton();
- + }else if (ACTION_SHOW_NAVIGATIONBAR.equals(action)){
- + //Log.d("wzh", "mBroadcastReceiver.action="+action);
- + if (mNavigationBarController.canShowNavigationBar()){
- + createNavigationBar(mBarRresult);
- + }
- }
- Trace.endSection();
- }
- diff --git a/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java b/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java
- old mode 100644
- new mode 100755
- index 658f4efbdb2f..c095df9b0adb
- --- a/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java
- +++ b/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java
- @@ -23,12 +23,14 @@ import static android.view.DisplayCutout.BOUNDS_POSITION_TOP;
-
- import android.annotation.NonNull;
- import android.content.Context;
- +import android.content.Intent;
- import android.content.res.Resources;
- import android.graphics.Rect;
- import android.graphics.Region;
- import android.hardware.display.DisplayManagerGlobal;
- import android.os.Handler;
- import android.os.SystemClock;
- +import android.util.Log;
- import android.util.Slog;
- import android.view.Display;
- import android.view.DisplayCutout;
- @@ -194,12 +196,15 @@ class SystemGesturesPointerEventListener implements PointerEventListener {
- if (mSwipeFireable) {
- final int swipe = detectSwipe(event);
- mSwipeFireable = swipe == SWIPE_NONE;
- + //Log.d("wzh", "onPointerEvent().MotionEvent.ACTION_MOVE.swipe="+swipe);
- if (swipe == SWIPE_FROM_TOP) {
- if (DEBUG) Slog.d(TAG, "Firing onSwipeFromTop");
- mCallbacks.onSwipeFromTop();
- + mContext.sendBroadcast(new Intent("action_show_navigationbar"));
- } else if (swipe == SWIPE_FROM_BOTTOM) {
- if (DEBUG) Slog.d(TAG, "Firing onSwipeFromBottom");
- mCallbacks.onSwipeFromBottom();
- + mContext.sendBroadcast(new Intent("action_show_navigationbar"));
- } else if (swipe == SWIPE_FROM_RIGHT) {
- if (DEBUG) Slog.d(TAG, "Firing onSwipeFromRight");
- mCallbacks.onSwipeFromRight();

2. 上面修改中有一行代码android:src="@drawable/ic_sysbar_hide"引用了一个ic_sysbar_hide.xml文件,该文件内容如下:其实就是那个隐藏按钮的矢量图代码
- <?xml version="1.0" encoding="utf-8"?>
- <vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="18dp"
- android:height="18dp"
- android:viewportWidth="35"
- android:viewportHeight="35">
-
- <path
- android:fillColor="#66cccccc"
- android:pathData="M21.314,25.837l9.898-9.9c0.782-0.782,2.049-0.782,2.829,0c0.78,0.781,0.781,2.049,0,2.831L22.73,30.079
- c-0.001,0.002-0.001,0.002-0.001,0.002c-0.39,0.391-0.902,0.586-1.415,0.586s-1.024-0.195-1.415-0.586L8.585,18.768
- c-0.782-0.781-0.779-2.049,0-2.831c0.781-0.782,2.049-0.782,2.831,0L21.314,25.837z"/>
- </vector>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。