Android5.0隐藏虚拟按键的方法

虚拟按键实现在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

     <!--ActionsCode(author:fanguoyong, add_code)      --> 
            <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"
                />
            <!--NEW_FEATURE:                                     -->
            <!--add virtual Volume Up button on navigation bar   --> 
            <!--ActionsCode(author:fanguoyong, add_code)      -->

            <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 重启电脑就可以了
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值