没有后退/主页/菜单按钮的全屏覆盖

时间:2015-06-18 11:22:14

标签: android user-interface

我有这个功能在我的活动上显示全屏黑色覆盖。模仿屏幕关闭行为。

private void showBlackOverlay() {
    Dialog dialog = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
    dialog.show();
}

但仍然可以看到后退/主页/菜单按钮。我该如何隐藏它们? 我还需要它来处理旧版本的android。

enter image description here

3 个答案:

答案 0 :(得分:1)

试试这个

View decorView = dialog.getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

答案 1 :(得分:1)

据我所知,从Android 4.4(API Level 19)开始,您可以这样做。您可以在此处查看详细信息:https://developer.android.com/training/system-ui/immersive.html

答案 2 :(得分:1)

尝试这样:

刚刚在我的nexus 7(Android 4.4.2)上试过这个代码并且工作正常

public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        if (hasFocus) {
            decorView
                    .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }
}