0

I plan to program an app with Android Studio. But this bar bothers me:

The status and notification bar

enter image description here

10
  • Add codes which you've tried. Commented Jan 16, 2020 at 15:43
  • Thank you for your prompt reply. I don't have any code on this topic yet because I haven't found anything
    – Luca
    Commented Jan 16, 2020 at 15:46
  • Do you want to remove the action bar? Commented Jan 16, 2020 at 15:51
  • In the picture you can see the bar I mean. So the bar with the time and battery level
    – Luca
    Commented Jan 16, 2020 at 15:57
  • 1
    Does this answer your question? Android Studio - Action Bar remove Commented Jan 16, 2020 at 16:00

2 Answers 2

1

If you are looking to just hide the status bar, it should be just adding this Java code to your activity's onCreate method:

View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
actionBar.hide();

You can find the Kotlin code here: https://developer.android.com/training/system-ui/status#41

If you are looking to make the app fullscreen with no Android UI you can use this Java code:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        hideSystemUI();
    }
}

private void hideSystemUI() {
    // Enables regular immersive mode.
    // For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
    // Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE
            // Set the content to appear under the system bars so that the
            // content doesn't resize when the system bars hide and show.
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            // Hide the nav bar and status bar
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN);
}

// Shows the system bars by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
    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);
}

You can find the Kotlin code here: https://developer.android.com/training/system-ui/immersive#EnableFullscreen

All the code snippets are from the Android documentation and not my own.

3
  • Thank you! That's exactly what I was looking for! But unfortunately everything is black at this point. And as soon as I click on the status bar it is back
    – Luca
    Commented Jan 16, 2020 at 17:15
  • Yes, the status bar will come back from hidden state if you tap or swipe on that side. I'm not sure there's a way around that. Also, what do you mean the screen is all black? Commented Jan 16, 2020 at 17:55
  • I checked it again. The black one is apparently on my cell phone. Thanks!
    – Luca
    Commented Jan 16, 2020 at 18:08
0

To remove status bar use this

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);

how to use ..

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
    }
}
2
  • Thanks a lot! That solved all problems!
    – Luca
    Commented Jan 17, 2020 at 13:37
  • Glad that i could help you
    – Dreamer
    Commented Jan 17, 2020 at 14:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.