Android 关闭虚拟按钮、底部导航条

Android 隐藏虚拟导航条(需要系统权限)

需要在 AndroidManifest.xml 中加入以下权限:

然后是关闭底部导航条的代码,我封装成了一个类,只需要在 onCreate 方法里调用该方法就行,该类如下:

import android.os.Build;

/**
 * 关闭显示导航条
 */
public class CloseBarUtil {

    /**
     * 关闭底部导航条
     */
    public static void closeBar() {
        try {
            // 需要root 权限
            Build.VERSION_CODES vc = new Build.VERSION_CODES();
            Build.VERSION vr = new Build.VERSION();
            String ProcID = "79";
            if (vr.SDK_INT >= vc.ICE_CREAM_SANDWICH) {
                ProcID = "42"; // ICS AND NEWER
            }
            // 需要root 权限
            Process proc = Runtime.getRuntime().exec(
                    new String[]{
                            "su",
                            "-c",
                            "service call activity " + ProcID
                                    + " s16 com.android.systemui"}); // WAS 79
            proc.waitFor();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 显示底部导航条
     */
    public static void showBar() {
        try {
            Process proc = Runtime.getRuntime().exec(
                    new String[]{"am", "startservice", "-n",
                            "com.android.systemui/.SystemUIService"});
            proc.waitFor();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

参考:https://www.cnblogs.com/yjq520/p/7243713.html



你可能感兴趣的:(Android)