第三方APK如何隐藏虚拟按键

本文介绍在全面屏时代,如何在Android设备上通过第三方APK控制底部虚拟按键RECENT、HOME、BACK的隐藏方法。通过定义与View.java API相同的数值,并在onCreate方法中设置系统UI可见性标志,实现特定虚拟按键的隐藏。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

全面屏时代,android设备已经很少有键盘的存在了,为了便捷,虚拟按键应运而生,当然iphone的手势控制也有一部分厂商移植到了android系统中。
本文主要是关于底部的三个虚拟按键RECENT、HOME、BACK对于第三方APK如何隐藏。
View.java的API显示,三个虚拟按键都是hide,即只有系统APK可以调用:

   /**
     * @hide
     *
     * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
     * out of the public fields to keep the undefined bits out of the developer's way.
     *
     * Flag to hide only the recent apps button. Don't use this
     * unless you're a special part of the system UI (i.e., setup wizard, keyguard).
     */
    public static final int STATUS_BAR_DISABLE_RECENT = 0x01000000;
    /**
     * @hide
     *
     * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
     * out of the public fields to keep the undefined bits out of the developer's way.
     *
     * Flag to hide only the home button.  Don't use this
     * unless you're a special part of the system UI (i.e., setup wizard, keyguard).
     */
    public static final int STATUS_BAR_DISABLE_HOME = 0x00200000;

    /**
     * @hide
     *
     * NOTE: This flag may only be used in subtreeSystemUiVisibility. It is masked
     * out of the public fields to keep the undefined bits out of the developer's way.
     *
     * Flag to hide only the back button. Don't use this
     * unless you're a special part of the system UI (i.e., setup wizard, keyguard).
     */
    public static final int STATUS_BAR_DISABLE_BACK = 0x00400000;
    

那第三方APK如何控制呢?

  // 定义与API中相同的数值
  private static final int STATUS_BAR_DISABLE_RECENT = 0x01000000;
  private static final int STATUS_BAR_DISABLE_HOME = 0x00200000;
  private static final int STATUS_BAR_DISABLE_BACK = 0x00400000;

@Override
protected void onCreate(Bundle icicle) {
	super.onCreate(icicle);
	...
	int flags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
	KeyguardManager mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
	flags |= STATUS_BAR_DISABLE_RECENT;
	Log.i(TAG, "disable recent!");

	getWindow()
        .getDecorView()
        .setSystemUiVisibility(flags);
	...
}

示例显示了如何隐藏RECENT虚拟按键。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值