Android Launcher 隐藏和开启底部虚拟按键(动态更改)

Posted 王睿丶

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android Launcher 隐藏和开启底部虚拟按键(动态更改)相关的知识,希望对你有一定的参考价值。

方法一:

这里我们可以写一个工具类 KeyButtonControl.java

class KeyButtonControl 

    private static final String TAG = "KeyButtonControl";
    public static final String STATUS_BAR_SERVICE = "statusbar";
    public static final String CLASS_STATUS_BAR_MANAGER = "android.app.StatusBarManager";
    public static final String METHOD_DISABLE = "disable";
    /*public static final int STATUS_BAR_DISABLE_HOME = 0x00200000;// 为View.STATUS_BAR_DISABLE_HOME的值
    public static final int STATUS_BAR_DISABLE_BACK = 0x00400000;// 为View.STATUS_BAR_DISABLE_BACK的值
    public static final int STATUS_BAR_DISABLE_RECENT = 0x01000000;// 为View.STATUS_BAR_DISABLE_RECENT的值
    public static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000;//整形标识
    public static final int STATUS_BAR_DISABLE_NONE = 0x00000000;//取消StatusBar所有disable属性,即还原到最最原始状态*/

    /**
     * 隐藏Back按键
     */
    public static void hideBackKey(Context mContext)
        try 
            @SuppressLint("WrongConstant") Object service = mContext.getSystemService(STATUS_BAR_SERVICE);
            Class<?> statusBarManager = Class.forName(CLASS_STATUS_BAR_MANAGER);
            Method disable = statusBarManager.getMethod(METHOD_DISABLE,
                    int.class);
            disable.invoke(service, 0x00400000);
            Log.i(TAG,"mdm hideBackKey");
         catch (Exception e) 
            e.printStackTrace();
        
    
//
    /**
     * 隐藏Home按键
     */
    public static void hideHomeKey(Context mContext)
        try 
            @SuppressLint("WrongConstant") Object service = mContext.getSystemService(STATUS_BAR_SERVICE);
            Class<?> statusBarManager = Class.forName(CLASS_STATUS_BAR_MANAGER);
            Method disable = statusBarManager.getMethod(METHOD_DISABLE,
                    int.class);
            disable.invoke(service, 0x00200000);
            Log.i(TAG,"mdm hideHomeKey");
         catch (Exception e) 
            e.printStackTrace();
        
    
//
    /**
     * 隐藏Task按键
     */
    public static void hideTaskKey(Context mContext)
        try 
            @SuppressLint("WrongConstant") Object service = mContext.getSystemService(STATUS_BAR_SERVICE);
            Class<?> statusBarManager = Class.forName(CLASS_STATUS_BAR_MANAGER);
            Method disable = statusBarManager.getMethod(METHOD_DISABLE,
                    int.class);
            disable.invoke(service, 0x00200000 | 0x00400000 | 0x01000000);
            Log.i(TAG,"mdm hideBackKey");
         catch (Exception e) 
            e.printStackTrace();
        
    

    /**
     * 隐藏全部按键
     */
    public static void hideAllKey(Context mContext)
        try 
            @SuppressLint("WrongConstant") Object service = mContext.getSystemService(STATUS_BAR_SERVICE);
            Class<?> statusBarManager = Class.forName(CLASS_STATUS_BAR_MANAGER);
            Method disable = statusBarManager.getMethod(METHOD_DISABLE,
                    int.class);
            disable.invoke(service, 0x00200000 | 0x00400000 | 0x01000000);
            Log.i(TAG,"mdm hideBackKey");
         catch (Exception e) 
            e.printStackTrace();
        
    

    /**
     * 显示全部按键
     */
    public static void showAllKey(Context mContext)
        try 
            @SuppressLint("WrongConstant") Object service = mContext.getSystemService(STATUS_BAR_SERVICE);
            Class<?> statusBarManager = Class.forName(CLASS_STATUS_BAR_MANAGER);
            Method disable = statusBarManager.getMethod(METHOD_DISABLE,
                    int.class);
            disable.invoke(service,  0x00000000);
            Log.i(TAG,"mdm showAllKey");
         catch (Exception e) 
            e.printStackTrace();
        
    

方法二:

frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
VISIBLE 更改为 INVISIBLE 即可

 		getBackButton().setVisibility(disableBack      ? View.INVISIBLE : View.VISIBLE);
        getHomeButton().setVisibility(disableHome      ? View.INVISIBLE : View.VISIBLE);
        getRecentsButton().setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE);

Launcher 开发系列:
Launcher 在底部导航栏添加一个“☰”按钮,点击弹出全部应用
Launcher 修改底部导航虚拟按键的位置
Launcher 隐藏和开启底部虚拟按键(动态更改)
Launcher 去掉全部应用界面的搜索框
Launcher 点击鼠标右键时,显示菜单栏
Launcher 自定义一个虚拟按键实现返回主页和打开全部应用两个功能

以上是关于Android Launcher 隐藏和开启底部虚拟按键(动态更改)的主要内容,如果未能解决你的问题,请参考以下文章

Android 6.0 隐藏Launcher3

Android 8.0 隐藏 Launcher3

Android Launcher 修改底部导航虚拟按键的位置

android launcher 之踩到的坑

隐藏APK在Launcher中的启动图标 android开发教程

android 底部导航 bottom navigation怎么设置图标和文字的距离