Why navigation bar is appearing in fullscreen apps when clicked on popup menu
Asked Answered
A

1

5

I have a fullscreen app:

MainActivity.java:

public class MainActivity extends AppCompatActivity {

@TargetApi(Build.VERSION_CODES.KITKAT)
private void removeControlBar(){
    View decorView = getWindow().getDecorView();
    decorView.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);
}
@Override
public void onResume(){
    super.onResume();
    removeControlBar();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="test.behy.android.test">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme.NoActionBar">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

it is fullscreen, but when I tap the popup menu the Navigation bar (bar including home, back) is appeared!

Question:

  • why it is so?
  • how can I fix it (to avoid the Navigation bar to be appeared)?

(I tried to remove titlebar and add an ImageButton with popup menu but it was exactly the same!) thanks for help!

Apteryx answered 21/12, 2015 at 11:44 Comment(3)
Please don't edit your original question to ask another question. If you have a new question, or even based this question, but you have other things to ask, please ask a new question instead of edit this one. However if your question (the part you asked) solved because Ms Yvette's answer, remember accept it. If it doesn't helpful, post your answer which can help others. Also check our tour or help center for more details.Contumacious
@Apteryx I'm facing the same problem. Have you found the solution yet?Actinomycete
@Apteryx Have you guys figured it out yet?Sumatra
B
13

You are trying to manage the sticky immersion by calling it in your onresume method. This means once the state has been changed it will not be reinstated until the activity next resumes.

Get rid of this private void removeControlBar()

You need to manage it via the windows onfocuschanged method.

This way alerts can be attended to and the nav bars etc will not return to the view when dealing with the pop ups.

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        decorView.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);
    }
}

The docs Use Sticky Immersion and a detailed explanation here.

Ballista answered 21/12, 2015 at 12:28 Comment(8)
by applying this my app is so: by click on menu the navigationbar is appeared by when I tap on a menu-item the bar is disappeared, better but not COMPLETELY disappearedApteryx
exactly when I tap on the popup menu, the navigationbar is also appeared and by tap on the menu-Item, it is disappearedApteryx
do you mean it is technically impossible to disappear the navigation bar during an app is running?Apteryx
@YvetteColomb I get the same problem as Behy. I use your code. But the navigation bar still appears when I click the popup menuActinomycete
@YvetteColomb You've got a point, but I'm developing a game and it's best if the system bars don't show up at all if possible, that is.Sumatra
@Apteryx use dropdown.setFocusable(false) to prevent nav bar popupKneepan
plus consider to add dropdown.setOutsideTouchable(true);Kneepan
@Kneepan feel free to add an edit. It's an old answer.Ballista

© 2022 - 2024 — McMap. All rights reserved.