MTK Android8.1隐藏导航栏按键功能实现
本功能一共涉及到的文件如下:
frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
vendor/mediatek/proprietary/packages/apps/SystemUI/res/layout/hide.xml
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/config.xml
vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw900dp/config.xml
vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw372dp/config.xml
vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw600dp/config.xml
1. 添加一个按键xml布局
alps/vendor/mediatek/proprietary/packages/apps/SystemUI/res/layout/hide.xml
可以直接copy home.xml然后做修改
<?xml version="1.0" encoding="utf-8"?>
<com.android.systemui.statusbar.policy.KeyButtonView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:systemui="http://schemas.android.com/apk/res-auto"
android:id="@+id/hide"
android:layout_width="@dimen/navigation_key_width"
android:layout_height="match_parent"
android:layout_weight="0"
systemui:keyCode="142"
android:scaleType="fitCenter"
android:contentDescription="@string/accessibility_key"
android:paddingTop="@dimen/home_padding"
android:paddingBottom="@dimen/home_padding"
android:paddingStart="@dimen/navigation_key_padding"
android:paddingEnd="@dimen/navigation_key_padding"
/>
2. 修改配置文件添加一个我们的按钮
vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/config.xml
vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw900dp/config.xml
vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw372dp/config.xml
vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw600dp/config.xml
修改添加一个 hide
即可(这里要是布局出现问题,可以全部内容改为以下内容)
<string name="config_navBarLayout" translatable="false">
left;back,home,recent;right
</string>
3. 添加初始化xml
vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarInflaterView.java
全局添加一个HIDE(和BACK,HOME一样)
public static final String HIDE = "hide";
然后在方法createView
中添加加载该xml的方法
private View createView(String buttonSpec, ViewGroup parent, LayoutInflater inflater) {
...
...
if (HOME.equals(button)) {
v = inflater.inflate(R.layout.home, parent, false);
// add code
} else if (HIDE.equals(button)) {
v = inflater.inflate(R.layout.hide, parent