Problems with popup menu and Immersive Mode

Asked

Viewed 46 times

1

I’ve set up my app to use Immersive Sticky Mode, but I also use some elements that are above the context of Activity and that when the user interacts with them, the app leaves Immersive Mode and the status bar is displayed again. These elements are a dialog box and a popup menu of 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 am unable to do the same with the popup menu. These are the creation and selection methods of the menu:

@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>

1 answer

0

Try to add that 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);
}
  • I already have it added to all my Activities and works perfectly for them, but the point is that it doesn’t work for the popup menu.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.