1.导航栏样式目前有,三键导航,也有全局手势导航,具体的设置是在setting里
setting里对应的 代码逻辑在packages\apps\Settings\src\com\android\settings\gestures\SystemNavigationPreferenceController.java
static boolean isOverlayPackageAvailable(Context context, String overlayPackage) { try { return context.getPackageManager().getPackageInfo(overlayPackage, 0) != null; } catch (PackageManager.NameNotFoundException e) { // Not found, just return unavailable return false; } } static boolean is2ButtonNavigationEnabled(Context context) { return NAV_BAR_MODE_2BUTTON == context.getResources().getInteger( com.android.internal.R.integer.config_navBarInteractionMode); } static boolean isGestureNavigationEnabled(Context context) { return NAV_BAR_MODE_GESTURAL == context.getResources().getInteger( com.android.internal.R.integer.config_navBarInteractionMode); }
系统默认的导航样式在配置文件中 frameworks\base\core\res\res\values\config.xml
<!-- 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">0</integer>
导航方式的切换在packages\apps\Settings\src\com\android\settings\gestures\SystemNavigationGestureSettings.java
static String getCurrentSystemNavigationMode(Context context) { if (SystemNavigationPreferenceController.isGestureNavigationEnabled(context)) { return KEY_SYSTEM_NAV_GESTURAL; } else if (SystemNavigationPreferenceController.is2ButtonNavigationEnabled(context)) { return KEY_SYSTEM_NAV_2BUTTONS; } else { return KEY_SYSTEM_NAV_3BUTTONS; } } @VisibleForTesting static void setCurrentSystemNavigationMode(IOverlayManager overlayManager, String key) { String overlayPackage = NAV_BAR_MODE_GESTURAL_OVERLAY; switch (key) { case KEY_SYSTEM_NAV_GESTURAL: overlayPackage = NAV_BAR_MODE_GESTURAL_OVERLAY; break; case KEY_SYSTEM_NAV_2BUTTONS: overlayPackage = NAV_BAR_MODE_2BUTTON_OVERLAY; break; case KEY_SYSTEM_NAV_3BUTTONS: overlayPackage = NAV_BAR_MODE_3BUTTON_OVERLAY; break; } try { overlayManager.setEnabledExclusiveInCategory(overlayPackage, USER_CURRENT); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } }
其中导航栏的具体方式定义在
frameworks\base\core\java\android\view\WindowManagerPolicyConstants.java
// Associated overlays for each nav bar mode String NAV_BAR_MODE_3BUTTON_OVERLAY = "com.android.internal.systemui.navbar.threebutton"; String NAV_BAR_MODE_2BUTTON_OVERLAY = "com.android.internal.systemui.navbar.twobutton"; String NAV_BAR_MODE_GESTURAL_OVERLAY = "com.android.internal.systemui.navbar.gestural";
使用Overlay替换原生导航栏
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.internal.systemui.navbar.gestural" android:versionCode="1" android:versionName="1.0"> <overlay android:targetPackage="android" android:category="com.android.internal.navigation_bar_mode" android:priority="1"/> <application android:label="@string/navigation_bar_mode_title" android:hasCode="false"/> </manifest>
具体导航栏的逻辑在