Problems with the popup menu and Immersive Mode

1

I've set up my application to use Immersive Sticky Mode, but I also use some elements that are above the Activity context and that when the user interacts with them, the application exits Immersive Mode and the status bar reverts to appears. These elements are a dialog box and a popup menu for a toolbar. I was able to prevent the status bar from appearing when the dialog was called through the following code within my showDialog method:

dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);

However, I can not do the same with the popup menu. These are the menu creation and selection methods:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_view, menu);

    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int choosenId = item.getItemId();

    switch (choosenId){
        case R.id.btn1:
            lblTitle.setText(R.string.btn1);

        break;
        case R.id.btn2:
            lblTitle.setText(R.string.btn2);

        break;
        case R.id.btn3:
            lblTitle.setText(R.string.btn3);

        break;
        case R.id.btn4:
            lblTitle.setText(R.string.btn4);

        break;
    }
    return super.onOptionsItemSelected(item);
}

And this is the xml of my toolbar:

       <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorBackgroundDarker"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay">

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="?attr/actionBarSize">

                <Button android:id="@+id/btnBack"
                    android:layout_width="35dp"
                    android:layout_height="35dp"
                    android:layout_centerVertical="true"
                    android:background="@mipmap/button_back_orange" />
            </RelativeLayout>

            <TextView android:id="@+id/lblTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/title"
                android:textSize="22sp"
                android:textColor="@color/white"
                style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
                android:layout_gravity="center"/>

        </android.support.v7.widget.Toolbar>
    
asked by anonymous 31.07.2018 / 19:32

1 answer

0

Try adding this to your Activity :

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
    getWindow().getDecorView().setSystemUiVisibility(
            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);
}
    
31.07.2018 / 19:42