IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> Android 8.1 如何动态修改导航栏宽度 -> 正文阅读

[移动开发]Android 8.1 如何动态修改导航栏宽度

需求:进入某个应用只保留左侧5个图标区域
代码路径:
frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
在PhoneWindowManager.java文件中beginLayoutLw()方法中修改,在每进入一个窗口的时候都会执行beginLayoutLw()方法,在该方法中会去重新初始化一下窗口的变量以及导航栏和状态栏,其中layoutNavigationBar初始化导航栏,layoutStatusBar初始化状态栏

@Override
public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
                          int displayRotation, int uiMode) {   
                boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
        displayRotation, uiMode, overscanLeft, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
        navAllowedHidden, statusBarExpandedNotKeyguard);
if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
        mDockLeft, mDockTop, mDockRight, mDockBottom));
updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing, displayRotation, uiMode);
if (updateSysUiVisibility) {
    updateSystemUiVisibilityLw();
}          
 }

在PhoneWindowManager.java文件中layoutNavigationBar方法中修改应用区域的宽度,right就是距离右边区域的宽度值

private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
        int uiMode, int overscanLeft, int overscanRight, int overscanBottom, Rect dcf,
        boolean navVisible, boolean navTranslucent, boolean navAllowedHidden,
        boolean statusBarExpandedNotKeyguard) {
            if (mNavigationBar != null) {
        boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
        // Force the navigation bar to its appropriate place and
        // size.  We need to do this directly, instead of relying on
        // it to bubble up from the nav bar, because this needs to
        // change atomically with screen rotations.
        mNavigationBarPosition = navigationBarPosition(displayWidth, displayHeight,
                displayRotation);
        if (mNavigationBarPosition == NAV_BAR_BOTTOM) {
             top = displayHeight - overscanBottom
                    - getNavigationBarHeight(displayRotation, uiMode);
                mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
}
            if (mNaviHided) {  // SPRD: add for dynamic navigationbar
                mTmpNavigationFrame.offset(0, getNavigationBarHeight(displayRotation, uiMode));
            }
            if(HIDE_BOTTOM_NAVI){
                mStableBottom = mStableFullscreenBottom = displayHeight;
            }else {
                mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
            }
            if (transientNavBarShowing) {
                mNavigationBarController.setBarShowingLw(true);
            } else if (navVisible) {
                mNavigationBarController.setBarShowingLw(true);
                mDockBottom = mTmpNavigationFrame.top;
                mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
                mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
            } else {
                // We currently want to hide the navigation UI - unless we expanded the status
                // bar.
                mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
            }
            if (navVisible && !navTranslucent && !navAllowedHidden
                    && !mNavigationBar.isAnimatingLw()
                    && !mNavigationBarController.wasRecentlyTranslucent()) {
                // If the opaque nav bar is currently requested to be visible,
                // and not in the process of animating on or off, then
                // we can tell the app that it is covered by it.
                mSystemBottom = mTmpNavigationFrame.top;
            }
        } else if (mNavigationBarPosition == NAV_BAR_RIGHT) {
            int left = displayWidth - overscanRight- getNavigationBarWidth(displayRotation, uiMode);
            mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
            if (mNaviHided) {  // SPRD: add for dynamic navigationbar
                mTmpNavigationFrame.offset(getNavigationBarWidth(displayRotation, uiMode), 0);
            }
                mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
            if (transientNavBarShowing) {
                mNavigationBarController.setBarShowingLw(true);
            } else if (navVisible) {
                mNavigationBarController.setBarShowingLw(true);
                mDockRight = mTmpNavigationFrame.left;
                mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
                mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
            } else {
                // We currently want to hide the navigation UI - unless we expanded the status
                // bar.
                mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
            }
            if (navVisible && !navTranslucent && !navAllowedHidden
                && !mNavigationBar.isAnimatingLw()
                && !mNavigationBarController.wasRecentlyTranslucent()) {
            // If the nav bar is currently requested to be visible,
            // and not in the process of animating on or off, then
            // we can tell the app that it is covered by it.
            mSystemRight = mTmpNavigationFrame.left;
            }
        }else if (mNavigationBarPosition == NAV_BAR_LEFT) {
            int right = overscanLeft + getNavigationBarWidth(displayRotation, uiMode);
            if (SystemProperties.getBoolean("persist.sys.navigationbar.right",false)){
                right = 110;
            }
                mTmpNavigationFrame.set(overscanLeft, 0, right, displayHeight);
                if (mNaviHided) {  // SPRD: add for dynamic navigationbar
                    mTmpNavigationFrame.offset(-getNavigationBarWidth(displayRotation, uiMode), 0);
        }
        mStableLeft = mStableFullscreenLeft = mTmpNavigationFrame.right;
        if (transientNavBarShowing) {
            mNavigationBarController.setBarShowingLw(true);
        } else if (navVisible) {
            mNavigationBarController.setBarShowingLw(true);
            mDockLeft = mTmpNavigationFrame.right;
            // TODO: not so sure about those:
            mRestrictedScreenLeft = mRestrictedOverscanScreenLeft = mDockLeft;
            mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
            mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
        } else {
            // We currently want to hide the navigation UI - unless we expanded the status
            // bar.
            mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
        }
        if (navVisible && !navTranslucent && !navAllowedHidden
            && !mNavigationBar.isAnimatingLw()
            && !mNavigationBarController.wasRecentlyTranslucent()) {
            // If the nav bar is currently requested to be visible,
            // and not in the process of animating on or off, then
            // we can tell the app that it is covered by it.
            mSystemLeft = mTmpNavigationFrame.right;
        }
    }
}
        }
        // Make sure the content and current rectangles are updated to
        // account for the restrictions from the navigation bar.
        mContentTop = mVoiceContentTop = mCurTop = mDockTop;
        mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
        mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
        mContentRight = mVoiceContentRight = mCurRight = mDockRight;
        mStatusBarLayer = mNavigationBar.getSurfaceLayer();
        // And compute the final frame.
        mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
        mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
        mTmpNavigationFrame, mTmpNavigationFrame);
        if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
            if (mNavigationBarController.checkHiddenLw()) {
            return true;
    }
    return false;
 }

备注:主要控制应用区域的函数

mTmpNavigationFrame.set(overscanLeft, 0, right, displayHeight);
  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2021-12-09 11:48:03  更:2021-12-09 11:49:04 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 7:36:47-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码