赞
踩
活动地址:CSDN21天学习挑战赛
在我们日常使用时,有很多情况下需要隐藏界面底部的导航栏。就比如我们现在手机的全屏应用,在这个时候就需要将导航栏给隐藏。基于此,Android原生系统就向我们提供了沉浸模式,而这个沉浸模式就是可以用来隐藏底部导航栏的,沉浸模式,通过点击屏幕或上滑等操作可以使导航栏显示。
主要核心代码:
frameworks\base\services\core\java\com\android\server\wm\DisplayPolicy.java
frameworks\base\core\res\res\values\demins.xml
framework/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
setSystemUiVisibility(int visibility):通过setSystemUiVisibility(int visibility)方法,可以改变状态栏或者其他系统UI的可见性。getWindow().getDecorView().setSystemUiVisibility(int visibility);
可供选择的参数:
@Override public void start() { mGroupManager = Dependency.get(NotificationGroupManager.class); mGroupAlertTransferHelper = Dependency.get(NotificationGroupAlertTransferHelper.class); mVisualStabilityManager = Dependency.get(VisualStabilityManager.class); mNotificationLogger = Dependency.get(NotificationLogger.class); mRemoteInputManager = Dependency.get(NotificationRemoteInputManager.class); mNotificationListener = Dependency.get(NotificationListener.class); mNotificationListener.registerAsSystemService(); mNetworkController = Dependency.get(NetworkController.class); mUserSwitcherController = Dependency.get(UserSwitcherController.class); mScreenLifecycle = Dependency.get(ScreenLifecycle.class); mScreenLifecycle.addObserver(mScreenObserver); mWakefulnessLifecycle = Dependency.get(WakefulnessLifecycle.class); mWakefulnessLifecycle.addObserver(mWakefulnessObserver); mBatteryController = Dependency.get(BatteryController.class); mDataSaverController = Dependency.get(DataSaverController.class); mAssistManager = Dependency.get(AssistManager.class); mUiModeManager = mContext.getSystemService(UiModeManager.class); mLockscreenUserManager = Dependency.get(NotificationLockscreenUserManager.class); mGutsManager = Dependency.get(NotificationGutsManager.class); mMediaManager = Dependency.get(NotificationMediaManager.class); mEntryManager = Dependency.get(NotificationEntryManager.class); mNotificationInterruptionStateProvider = Dependency.get(NotificationInterruptionStateProvider.class); mViewHierarchyManager = Dependency.get(NotificationViewHierarchyManager.class); mForegroundServiceController = Dependency.get(ForegroundServiceController.class); mAppOpsController = Dependency.get(AppOpsController.class); mZenController = Dependency.get(ZenModeController.class); mKeyguardViewMediator = getComponent(KeyguardViewMediator.class); mColorExtractor = Dependency.get(SysuiColorExtractor.class); mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class); mNavigationBarController = Dependency.get(NavigationBarController.class); mBubbleController = Dependency.get(BubbleController.class); mBubbleController.setExpandListener(mBubbleExpandListener); mActivityIntentHelper = new ActivityIntentHelper(mContext); KeyguardSliceProvider sliceProvider = KeyguardSliceProvider.getAttachedInstance(); if (sliceProvider != null) { sliceProvider.initDependencies(mMediaManager, mStatusBarStateController); } else { Log.w(TAG, "Cannot init KeyguardSliceProvider dependencies"); } mColorExtractor.addOnColorsChangedListener(this); mStatusBarStateController.addCallback(this, SysuiStatusBarStateController.RANK_STATUS_BAR); mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); mDreamManager = IDreamManager.Stub.asInterface( ServiceManager.checkService(DreamService.DREAM_SERVICE)); /* UNISOC: Bug 1074234, 885650, Super power feature @{ */ if(SprdPowerManagerUtil.SUPPORT_SUPER_POWER_SAVE){ int mode = SprdPowerManagerUtil.getPowerSaveModeInternal(); mPowerSaveMode = mode; curMode = mode; } /* @} */ mDisplay = mWindowManager.getDefaultDisplay(); mDisplayId = mDisplay.getDisplayId(); updateDisplaySize(); mVibrateOnOpening = mContext.getResources().getBoolean( R.bool.config_vibrateOnIconAnimation); mVibratorHelper = Dependency.get(VibratorHelper.class); DateTimeView.setReceiverHandler(Dependency.get(Dependency.TIME_TICK_HANDLER)); putComponent(StatusBar.class, this); // start old BaseStatusBar.start(). mWindowManagerService = WindowManagerGlobal.getWindowManagerService(); mDevicePolicyManager = (DevicePolicyManager) mContext.getSystemService( Context.DEVICE_POLICY_SERVICE); mAccessibilityManager = (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE); mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mKeyguardUpdateMonitor = KeyguardUpdateMonitor.getInstance(mContext); mBarService = IStatusBarService.Stub.asInterface( ServiceManager.getService(Context.STATUS_BAR_SERVICE)); mRecents = getComponent(Recents.class); mKeyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE); // Connect in to the status bar manager service mCommandQueue = getComponent(CommandQueue.class); mCommandQueue.addCallback(this); RegisterStatusBarResult result = null; try { result = mBarService.registerStatusBar(mCommandQueue); } catch (RemoteException ex) { ex.rethrowFromSystemServer(); } createAndAddWindows(result); // Make sure we always have the most current wallpaper info. IntentFilter wallpaperChangedFilter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED); mContext.registerReceiverAsUser(mWallpaperChangedReceiver, UserHandle.ALL, wallpaperChangedFilter, null /* broadcastPermission */, null /* scheduler */); mWallpaperChangedReceiver.onReceive(mContext, null); // Set up the initial notification state. This needs to happen before CommandQueue.disable() setUpPresenter(); setSystemUiVisibility(mDisplayId, result.mSystemUiVisibility, result.mFullscreenStackSysUiVisibility, result.mDockedStackSysUiVisibility, 0xffffffff, result.mFullscreenStackBounds, result.mDockedStackBounds, result.mNavbarColorManagedByIme); // StatusBarManagerService has a back up of IME token and it's restored here. setImeWindowStatus(mDisplayId, result.mImeToken, result.mImeWindowVis, result.mImeBackDisposition, result.mShowImeSwitcher); // Set up the initial icon state int numIcons = result.mIcons.size(); for (int i = 0; i < numIcons; i++) { mCommandQueue.setIcon(result.mIcons.keyAt(i), result.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.mSystemUiVisibility, result.mImeWindowVis)); } IntentFilter internalFilter = new IntentFilter(); internalFilter.addAction(BANNER_ACTION_CANCEL); internalFilter.addAction(BANNER_ACTION_SETUP); mContext.registerReceiver(mBannerActionBroadcastReceiver, internalFilter, PERMISSION_SELF, null); IWallpaperManager wallpaperManager = IWallpaperManager.Stub.asInterface( ServiceManager.getService(Context.WALLPAPER_SERVICE)); try { wallpaperManager.setInAmbientMode(false /* ambientMode */, 0L /* duration */); } catch (RemoteException e) { // Just pass, nothing critical. } // end old BaseStatusBar.start(). // Lastly, call to the icon policy to install/update all the icons. mIconPolicy = new PhoneStatusBarPolicy(mContext, mIconController); mSignalPolicy = new StatusBarSignalPolicy(mContext, mIconController); mUnlockMethodCache = UnlockMethodCache.getInstance(mContext); mUnlockMethodCache.addListener(this); startKeyguard(); mKeyguardUpdateMonitor.registerCallback(mUpdateCallback); putComponent(DozeHost.class, mDozeServiceHost); mScreenPinningRequest = new ScreenPinningRequest(mContext); mFalsingManager = FalsingManagerFactory.getInstance(mContext); Dependency.get(ActivityStarterDelegate.class).setActivityStarterImpl(this); Dependency.get(ConfigurationController.class).addCallback(this); // set the initial view visibility Dependency.get(InitController.class).addPostInitTask(this::updateAreThereNotifications); int disabledFlags1 = result.mDisabledFlags1; int disabledFlags2 = result.mDisabledFlags2; Dependency.get(InitController.class).addPostInitTask( () -> setUpDisableFlags(disabledFlags1, disabledFlags2)); // UNISOC: BUG 1156257 add screen resolution observer to control NavigationBarView mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(ACTION_SR_CHANGING), false, mScreenResolutionObserver); CommonUtils.setRegionOrLongshotMode(mContext.getContentResolver(), 0); } // ================================================================================ // Constructing the view // ================================================================================ protected void makeStatusBarView(@Nullable RegisterStatusBarResult result) { final Context context = mContext; updateDisplaySize(); // populates mDisplayMetrics updateResources(); updateTheme(); inflateStatusBarWindow(context); mStatusBarWindow.setService(this); mStatusBarWindow.setOnTouchListener(getStatusBarWindowTouchListener()); // TODO: Deal with the ugliness that comes from having some of the statusbar broken out // into fragments, but the rest here, it leaves some awkward lifecycle and whatnot. mNotificationPanel = mStatusBarWindow.findViewById(R.id.notification_panel); mStackScroller = mStatusBarWindow.findViewById(R.id.notification_stack_scroller); mZenController.addCallback(this); NotificationListContainer notifListContainer = (NotificationListContainer) mStackScroller; mNotificationLogger.setUpWithContainer(notifListContainer); mNotificationIconAreaController = SystemUIFactory.getInstance() .createNotificationIconAreaController(context, this, mStatusBarStateController); inflateShelf(); mNotificationIconAreaController.setupShelf(mNotificationShelf); Dependency.get(DarkIconDispatcher.class).addDarkReceiver(mNotificationIconAreaController); // Allow plugins to reference DarkIconDispatcher and StatusBarStateController Dependency.get(PluginDependencyProvider.class) .allowPluginDependency(DarkIconDispatcher.class); Dependency.get(PluginDependencyProvider.class) .allowPluginDependency(StatusBarStateController.class); FragmentHostManager.get(mStatusBarWindow) .addTagListener(CollapsedStatusBarFragment.TAG, (tag, fragment) -> { CollapsedStatusBarFragment statusBarFragment = (CollapsedStatusBarFragment) fragment; statusBarFragment.initNotificationIconArea(mNotificationIconAreaController); PhoneStatusBarView oldStatusBarView = mStatusBarView; mStatusBarView = (PhoneStatusBarView) fragment.getView(); mStatusBarView.setBar(this); mStatusBarView.setPanel(mNotificationPanel); mStatusBarView.setScrimController(mScrimController); // CollapsedStatusBarFragment re-inflated PhoneStatusBarView and both of // mStatusBarView.mExpanded and mStatusBarView.mBouncerShowing are false. // PhoneStatusBarView's new instance will set to be gone in // PanelBar.updateVisibility after calling mStatusBarView.setBouncerShowing // that will trigger PanelBar.updateVisibility. If there is a heads up showing, // it needs to notify PhoneStatusBarView's new instance to update the correct // status by calling mNotificationPanel.notifyBarPanelExpansionChanged(). if (mHeadsUpManager.hasPinnedHeadsUp()) { mNotificationPanel.notifyBarPanelExpansionChanged(); } mStatusBarView.setBouncerShowing(mBouncerShowing); if (oldStatusBarView != null) { float fraction = oldStatusBarView.getExpansionFraction(); boolean expanded = oldStatusBarView.isExpanded(); mStatusBarView.panelExpansionChanged(fraction, expanded); } HeadsUpAppearanceController oldController = mHeadsUpAppearanceController; if (mHeadsUpAppearanceController != null) { // This view is being recreated, let's destroy the old one mHeadsUpAppearanceController.destroy(); } mHeadsUpAppearanceController = new HeadsUpAppearanceController( mNotificationIconAreaController, mHeadsUpManager, mStatusBarWindow); mHeadsUpAppearanceController.readFrom(oldController); mStatusBarWindow.setStatusBarView(mStatusBarView); updateAreThereNotifications(); checkBarModes(); }).getFragmentManager() .beginTransaction() .replace(R.id.status_bar_container, new CollapsedStatusBarFragment(), CollapsedStatusBarFragment.TAG) .commit(); mIconController = Dependency.get(StatusBarIconController.class); mHeadsUpManager = new HeadsUpManagerPhone(context, mStatusBarWindow, mGroupManager, this, mVisualStabilityManager); Dependency.get(ConfigurationController.class).addCallback(mHeadsUpManager); mHeadsUpManager.addListener(this); mHeadsUpManager.addListener(mNotificationPanel); mHeadsUpManager.addListener(mGroupManager); mHeadsUpManager.addListener(mGroupAlertTransferHelper); mHeadsUpManager.addListener(mVisualStabilityManager); mAmbientPulseManager.addListener(this); mAmbientPulseManager.addListener(mGroupManager); mAmbientPulseManager.addListener(mGroupAlertTransferHelper); mNotificationPanel.setHeadsUpManager(mHeadsUpManager); mGroupManager.setHeadsUpManager(mHeadsUpManager); mGroupAlertTransferHelper.setHeadsUpManager(mHeadsUpManager); mNotificationLogger.setHeadsUpManager(mHeadsUpManager); putComponent(HeadsUpManager.class, mHeadsUpManager); createNavigationBar(result); if (ENABLE_LOCKSCREEN_WALLPAPER) { mLockscreenWallpaper = new LockscreenWallpaper(mContext, this, mHandler); } mKeyguardIndicationController = SystemUIFactory.getInstance().createKeyguardIndicationController(mContext, mStatusBarWindow.findViewById(R.id.keyguard_indication_area), mStatusBarWindow.findViewById(R.id.lock_icon)); mNotificationPanel.setKeyguardIndicationController(mKeyguardIndicationController); mAmbientIndicationContainer = mStatusBarWindow.findViewById( R.id.ambient_indication_container); // TODO: Find better place for this callback. mBatteryController.addCallback(new BatteryStateChangeCallback() { @Override public void onPowerSaveChanged(boolean isPowerSave) { mHandler.post(mCheckBarModes); if (mDozeServiceHost != null) { mDozeServiceHost.firePowerSaveChanged(isPowerSave); } } @Override public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { // noop } }); mAutoHideController = Dependency.get(AutoHideController.class); mAutoHideController.setStatusBar(this); mLightBarController = Dependency.get(LightBarController.class); ScrimView scrimBehind = mStatusBarWindow.findViewById(R.id.scrim_behind); ScrimView scrimInFront = mStatusBarWindow.findViewById(R.id.scrim_in_front); mScrimController = SystemUIFactory.getInstance().createScrimController( scrimBehind, scrimInFront, mLockscreenWallpaper, (state, alpha, color) -> mLightBarController.setScrimState(state, alpha, color), scrimsVisible -> { if (mStatusBarWindowController != null) { mStatusBarWindowController.setScrimsVisibility(scrimsVisible); } if (mStatusBarWindow != null) { mStatusBarWindow.onScrimVisibilityChanged(scrimsVisible); } }, DozeParameters.getInstance(mContext), mContext.getSystemService(AlarmManager.class)); mNotificationPanel.initDependencies(this, mGroupManager, mNotificationShelf, mHeadsUpManager, mNotificationIconAreaController, mScrimController); mDozeScrimController = new DozeScrimController(DozeParameters.getInstance(context)); BackDropView backdrop = mStatusBarWindow.findViewById(R.id.backdrop); mMediaManager.setup(backdrop, backdrop.findViewById(R.id.backdrop_front), backdrop.findViewById(R.id.backdrop_back), mScrimController, mLockscreenWallpaper); // Other icons mVolumeComponent = getComponent(VolumeComponent.class); mNotificationPanel.setUserSetupComplete(mUserSetup); if (UserManager.get(mContext).isUserSwitcherEnabled()) { createUserSwitcher(); } mNotificationPanel.setLaunchAffordanceListener( mStatusBarWindow::onShowingLaunchAffordanceChanged); // Set up the quick settings tile panel View container = mStatusBarWindow.findViewById(R.id.qs_frame); if (container != null) { FragmentHostManager fragmentHostManager = FragmentHostManager.get(container); ExtensionFragmentListener.attachExtensonToFragment(container, QS.TAG, R.id.qs_frame, Dependency.get(ExtensionController.class) .newExtension(QS.class) .withPlugin(QS.class) .withDefault(this::createDefaultQSFragment) .build()); mBrightnessMirrorController = new BrightnessMirrorController(mStatusBarWindow, (visible) -> { mBrightnessMirrorVisible = visible; updateScrimController(); }); fragmentHostManager.addTagListener(QS.TAG, (tag, f) -> { QS qs = (QS) f; if (qs instanceof QSFragment) { mQSPanel = ((QSFragment) qs).getQsPanel(); mQSPanel.setBrightnessMirror(mBrightnessMirrorController); mFooter = ((QSFragment) qs).getFooter(); } }); } mReportRejectedTouch = mStatusBarWindow.findViewById(R.id.report_rejected_touch); if (mReportRejectedTouch != null) { updateReportRejectedTouchVisibility(); mReportRejectedTouch.setOnClickListener(v -> { Uri session = mFalsingManager.reportRejectedTouch(); if (session == null) { return; } StringWriter message = new StringWriter(); message.write("Build info: "); message.write(SystemProperties.get("ro.build.description")); message.write("\nSerial number: "); message.write(SystemProperties.get("ro.serialno")); message.write("\n"); PrintWriter falsingPw = new PrintWriter(message); FalsingLog.dump(falsingPw); falsingPw.flush(); startActivityDismissingKeyguard(Intent.createChooser(new Intent(Intent.ACTION_SEND) .setType("*/*") .putExtra(Intent.EXTRA_SUBJECT, "Rejected touch report") .putExtra(Intent.EXTRA_STREAM, session) .putExtra(Intent.EXTRA_TEXT, message.toString()), "Share rejected touch report") .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), true /* onlyProvisioned */, true /* dismissShade */); }); } PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); if (!pm.isScreenOn()) { mBroadcastReceiver.onReceive(mContext, new Intent(Intent.ACTION_SCREEN_OFF)); } mGestureWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "GestureWakeLock"); mVibrator = mContext.getSystemService(Vibrator.class); int[] pattern = mContext.getResources().getIntArray( R.array.config_cameraLaunchGestureVibePattern); mCameraLaunchGestureVibePattern = new long[pattern.length]; for (int i = 0; i < pattern.length; i++) { mCameraLaunchGestureVibePattern[i] = pattern[i]; } // receive broadcasts IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG); /* UNISOC: Bug 1074234, 885650, Super power feature @{ */ if(SprdPowerManagerUtil.SUPPORT_SUPER_POWER_SAVE){ filter.addAction(SprdPowerManagerUtil.ACTION_POWEREX_SAVE_MODE_CHANGED); } /* @} */ context.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null); IntentFilter demoFilter = new IntentFilter(); if (DEBUG_MEDIA_FAKE_ARTWORK) { demoFilter.addAction(ACTION_FAKE_ARTWORK); } demoFilter.addAction(ACTION_DEMO); context.registerReceiverAsUser(mDemoReceiver, UserHandle.ALL, demoFilter, android.Manifest.permission.DUMP, null); // listen for USER_SETUP_COMPLETE setting (per-user) mDeviceProvisionedController.addCallback(mUserSetupObserver); mUserSetupObserver.onUserSetupChanged(); // disable profiling bars, since they overlap and clutter the output on app windows ThreadedRenderer.overrideProperty("disableProfileBars", "true"); // Private API call to make the shadows look better for Recents ThreadedRenderer.overrideProperty("ambientRatio", String.valueOf(1.5f)); /* UNISOC: Bug 1074234, 885650, Super power feature @{ */ if(SprdPowerManagerUtil.SUPPORT_SUPER_POWER_SAVE && mNotificationPanel != null){ int mode = SprdPowerManagerUtil.getPowerSaveModeInternal(); if(mFooter != null){ mFooter.setPowerSaveMode(mode); } if(mQSPanel != null){ mQSPanel.setPowerSaveMode(mode); } if (mNotificationPanel != null){ mNotificationPanel.setPowerSaveMode(mode); } /* UNISOC: Modify for bug974161 {@ */ mNavigationBarController.setPowerSaveMode(mode); /* @} */ } /* @} */ /* UNISOC: Bug 1104465 add for screen pinning @{ */ mScreenPinningNotify = new ScreenPinningNotify(mContext); /* @} */ } 在makeStatusBarView(@Nullable RegisterStatusBarResult result)中的 createNavigationBar(result); 就是加载导航栏 直接注释掉就可以了
public boolean hasNavigationBar() { return mHasNavigationBar; } /** * Return the display height available after excluding any screen * decorations that could never be removed in Honeycomb. That is, system bar or * button bar. */ public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode, DisplayCutout displayCutout) { int height = fullHeight; if (hasNavigationBar()) { final int navBarPosition = navigationBarPosition(fullWidth, fullHeight, rotation); if (navBarPosition == NAV_BAR_BOTTOM) { height -= getNavigationBarHeight(rotation, uiMode); } } if (displayCutout != null) { height -= displayCutout.getSafeInsetTop() + displayCutout.getSafeInsetBottom(); } return height; } /** * Return the display width available after excluding any screen * decorations that could never be removed in Honeycomb. That is, system bar or * button bar. */ public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode, DisplayCutout displayCutout) { int width = fullWidth; if (hasNavigationBar()) { final int navBarPosition = navigationBarPosition(fullWidth, fullHeight, rotation); if (navBarPosition == NAV_BAR_LEFT || navBarPosition == NAV_BAR_RIGHT) { width -= getNavigationBarWidth(rotation, uiMode); } } if (displayCutout != null) { width -= displayCutout.getSafeInsetLeft() + displayCutout.getSafeInsetRight(); } return width; } 根据hasNavigationBar()判断是否有导航栏来就是显示屏幕宽度和高度 所以修改为: public boolean hasNavigationBar() { - return mHasNavigationBar; + return false; }
设置导航栏高度为0
路径:frameworks\base\core\res\res\values\demins.xml
<dimen name="navigation_bar_height">48dp</dimen>
navigation_bar_height 导航栏高度设置为0
加油学习!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。