欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-07-03 14:59:25
全面屏时代,android设备已经很少有键盘的存在了,为了便捷,虚拟按键应运而生,当然iphone的手势控制也有一部分厂商移植到了android系统中。本文主要是关于底部的三个虚拟按键RECENT、HOME、BACK对于第三方APK如何隐藏。View.java的API显示,三个虚拟按键都是hide,即只有系统APK可以调用: /** * @hide * * NOTE: This flag may only be used in subtreeSystemUiVisib...

全面屏时代,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虚拟按键。

本文地址:https://blog.csdn.net/qq_28534581/article/details/107959263