关闭Android PopUpWindow对象使状态栏可见。怎么阻止这个?

时间:2017-06-01 12:50:02

标签: android statusbar popupwindow android-popupwindow

我有一个全屏的活动。我正在使用下面的代码(我在onResume方法中调用)进行全屏活动

int currentApiVersion = Build.VERSION.SDK_INT;

    final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

    // This work only for android 4.4+
    if (currentApiVersion >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().getDecorView().setSystemUiVisibility(flags);
        // Code below is to handle presses of Volume up or Volume down.
        // Without this, after pressing volume buttons, the navigation bar will
        // show up and won't hide
        final View decorView = activity.getWindow().getDecorView();
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                    decorView.setSystemUiVisibility(flags);
                }
            }
        });
    }

在这个Activity中,我打开一个PopUpWindow对象。但打开此状态后,状态栏变为可见。如何阻止这个?

为了显示PopUpWindow,我使用以下代码:

popupWindow = new PopupWindow(layout,RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT,true);             popupWindow.showAtLocation(layout,Gravity.NO_GRAVITY,0,0);

我无法弄清楚,这些方法有什么问题。请帮忙。提前谢谢。

1 个答案:

答案 0 :(得分:2)

更改实施方式并在onCreate Activity上的setContentView()中应用此代码,并确保在OnCreate @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.splash_layout); } 之前添加了此内容>

dataGridView1.CurrentCell = dataGridView1.Rows.Cast<DataGridViewRow>().Last().Cells[0];