android 底部返回键等虚拟按键显示隐藏

视频播放器中,全屏播放我们一般需要隐藏虚拟按键,竖屏时显示虚拟按键,下面附上代码:

竖屏显示虚拟按键:

    //显示虚拟按键
    if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) {
        //低版本sdk
        View v = getWindow().getDecorView();
        v.setSystemUiVisibility(View.VISIBLE);
    } else if (Build.VERSION.SDK_INT >= 19) {
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
    }

横屏隐藏虚拟按键:

 //隐藏虚拟按键
    if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) {
        View v = getWindow().getDecorView();
        v.setSystemUiVisibility(View.GONE);
    } else if (Build.VERSION.SDK_INT >= 19) {
        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY 
                | View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
    }   

猜你喜欢

转载自blog.csdn.net/shanshan_1117/article/details/80667679