虚拟按键实现在android/frameworks/base/packages/SystemUI/ 源码中定义的,要隐藏虚拟按键就需要找到其定义的布局文件和功能定义文件.下面是三种实现方法
方法一: device/actions/cubieboard6/device.mk 中加入 qemu.hw.mainkeys=1 编译完后后会在系统 build.prop中看见
方法二: frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java 中删除addNavigationBar();
方法三:
布局文件:res/ layout-sw600/ navigation_bar.xml
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/volume_down"
android:layout_width="80dp" android:paddingStart="0dp" android:paddingEnd="0dp"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_volume_down"
systemui:keyCode="25"
android:layout_weight="0"
android:scaleType="center"
android:contentDescription="@string/accessibility_volume_down"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/back"
android:layout_width="80dp" android:paddingStart="0dp" android:paddingEnd="0dp"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_back"
systemui:keyCode="4"
android:layout_weight="0"
android:scaleType="center"
android:contentDescription="@string/accessibility_back"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/home"
android:layout_width="80dp" android:paddingStart="0dp" android:paddingEnd="0dp"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_home"
systemui:keyCode="3"
systemui:keyRepeat="false"
android:layout_weight="0"
android:scaleType="center"
android:contentDescription="@string/accessibility_home"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/recent_apps"
android:layout_width="80dp" android:paddingStart="0dp" android:paddingEnd="0dp"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_recent"
android:layout_weight="0"
android:scaleType="center"
android:contentDescription="@string/accessibility_recent"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/volume_up"
android:layout_width="80dp" android:paddingStart="0dp" android:paddingEnd="0dp"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_volume_up"
systemui:keyCode="24"
android:layout_weight="0"
android:scaleType="center"
android:contentDescription="@string/accessibility_volume_up"
/>
<Space
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
/>
功能文件:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java’
修改NavigationBarView.java 文件
//获取配置文件ro.systemui.volumekey从build.prop中
// mVolumeDisplayFlag = SystemProperties.get("ro.systemui.volumekey", "enable").equals("enable"); **----需要注释掉**
**//下面是设置5个虚拟按键不可见**
getBackButton() .setVisibility(View.INVISIBLE);
getHomeButton() .setVisibility(View.INVISIBLE);
getRecentsButton().setVisibility(View.INVISIBLE);
if((getVolumeUpButton() != null) && (getVolumeDownButton() != null)){
if(mVolumeDisplayFlag){
getVolumeUpButton().setVisibility(View.INVISIBLE);
getVolumeDownButton().setVisibility(View.INVISIBLE);
} else{
getVolumeUpButton().setVisibility(View.GONE);
getVolumeDownButton().setVisibility(View.GONE);
}
}
注意:改完源码后 ,使用以下指令会生成
out/target/product/cubieboard6/data/app/SystemUITests/SystemUITests.apk
source build/envsetup;lunch ---选择你的编译平台
mmm /frameworks/base/packages/SystemUI
你需要将SystemUITests.apk修改成 SystemUI.apk(系统中默认安装名称为SystemUI.apk),然后将生成的apk push进系统.
adb push out/target/product/cubieboard6/data/app/SystemUITests/SystemUITests.apk /system/priv-app/SystemUI/
adb reboot 重启电脑就可以了