少于 1 分钟阅读 次阅读

概要:本文介绍了在 Android 13 上如何通过修改 config.xml 配置文件,启用手势导航模式,从而隐藏导航栏。并分析了相关代码的解析和生效原理。

1. 具体修改

修改路径:
device/rockchip/rk3588/overlay/frameworks/base/core/res/res/values/config.xml

config_navBarInteractionMode 修改为模式 2,即启用手势导航,导航栏将自动隐藏。

<!-- Controls the navigation bar interaction mode:
         0: 3 button mode (back, home, overview buttons)
         1: 2 button mode (back, home buttons + swipe up for overview)
         2: gestures only for back, home and overview -->
<integer name="config_navBarInteractionMode">2</integer>

2. 生效原理

2.1 配置解析

上述 config_navBarInteractionMode 的值会在以下文件中进行解析:
路径:
frameworks/base/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationModeController.java

在 Android 开发中,​Overlay 机制允许覆盖源码中的系统设置,以下代码展示了如何解析该配置:

private int getCurrentInteractionMode(Context context) {
    int mode = context.getResources().getInteger(
            com.android.internal.R.integer.config_navBarInteractionMode); // 在此处解析
    if (DEBUG) {
        Log.d(TAG, "getCurrentInteractionMode: mode=" + mode
                + " contextUser=" + context.getUserId());
    }
    return mode;
}

2.2 更新手势设置

解析得到的 mode 值会用于更新手势导航的设置:

public void updateCurrentInteractionMode(boolean notify) {
    mCurrentUserContext = getCurrentUserContext();
    int mode = getCurrentInteractionMode(mCurrentUserContext);
    mUiBgExecutor.execute(() ->
        Settings.Secure.putString(mCurrentUserContext.getContentResolver(),
                Secure.NAVIGATION_MODE, String.valueOf(mode)));
    if (DEBUG) {
        Log.d(TAG, "updateCurrentInteractionMode: mode=" + mode);
        dumpAssetPaths(mCurrentUserContext);
    }

    if (notify) {
        for (int i = 0; i < mListeners.size(); i++) {
            mListeners.get(i).onNavigationModeChanged(mode);
        }
    }
}

留下评论