Android 7.1 虚拟按键(NavigationBar)源码分析 控件加载、属性控制隐藏
https://blog.csdn.net/kuaiguixs/article/details/78291695 Android 7.0 虚拟按键(NavigationBar)源码分析 之 View的创建流程
一.主要的几个类
//实现 单个虚拟按键的 自定义ImageView frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java //虚拟按键的容器,实现整个 虚拟导航条的 自定义LinearLayout frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java //动态加载虚拟按键,放入NavigationBarView frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java //虚拟导航条对应的布局文件 frameworks/base/packages/SystemUI/res/layout/navigation_bar.xml //实现虚拟按键的点击效果 frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
二. inflateNavigationBarView 方法,它加载了布局 R.layout.navigation_bar,作为虚拟按键的容器 属性控制隐藏
--- a/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java +++ b/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java @@ -32,6 +32,7 @@ import android.widget.Space; import com.android.systemui.R; import com.android.systemui.statusbar.policy.KeyButtonView; import com.android.systemui.tuner.TunerService; +import android.os.SystemProperties; import java.util.Objects; public class NavigationBarInflaterView extends FrameLayout implements TunerService.Tunable { @@ -265,45 +266,59 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi String button = extractButton(buttonSpec); View v = null; if (HOME.equals(button)) { - v = inflater.inflate(R.layout.home, parent, false); - if (landscape && isSw600Dp()) { - setupLandButton(v); - } + if(SystemProperties.get("persist.navi.home","true").equals("true")){ + v = inflater.inflate(R.layout.home, parent, false); + if (landscape && isSw600Dp()) { + setupLandButton(v); + } + } } else if (BACK.equals(button)) { + if(SystemProperties.get("ro.navi.back","true").equals("true")){ v = inflater.inflate(R.layout.back, parent, false); if (landscape && isSw600Dp()) { setupLandButton(v); } + } } else if (RECENT.equals(button)) { + if(SystemProperties.get("ro.navi.recent","true").equals("true")){ v = inflater.inflate(R.layout.recent_apps, parent, false); if (landscape && isSw600Dp()) { setupLandButton(v); } + } } else if (SCREENSHOT.equals(button)) { v = inflater.inflate(R.layout.screenshot, parent, false); if (landscape && isSw600Dp()) { setupLandButton(v); } } else if (VOLUME_ADD.equals(button)) { + if(SystemProperties.get("ro.navi.volume_add","true").equals("true")){ v = inflater.inflate(R.layout.volume_add, parent, false); if (landscape && isSw600Dp()) { setupLandButton(v); } + } } else if (VOLUME_SUB.equals(button)) { + if(SystemProperties.get("ro.navi.volume_sub","true").equals("true")){ v = inflater.inflate(R.layout.volume_sub, parent, false); if (landscape && isSw600Dp()) { setupLandButton(v); } + } }else if (POWER_DOWN.equals(button)) { + if(SystemProperties.get("ro.navi.powerdown","true").equals("true")){ v = inflater.inflate(R.layout.powerdown, parent, false); if (landscape && isSw600Dp()) { setupLandButton(v); } + } }else if (HIDE_BAR.equals(button)) { + if(SystemProperties.get("ro.navi.hide_bar","true").equals("true")){ v = inflater.inflate(R.layout.hide_bar, parent, false); if (landscape && isSw600Dp()) { setupLandButton(v); } + } } else if (MENU_IME.equals(button)) { v = inflater.inflate(R.layout.menu_ime, parent, false); } else if (NAVSPACE.equals(button)) { @@ -321,6 +336,9 @@ public class NavigationBarInflaterView extends FrameLayout implements TunerServi } else { return null; } + if(v == null){ + return null; + } if (size != 0) { ViewGroup.LayoutParams params = v.getLayoutParams();