0

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

The status and notification bar

enter image description here

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Luca
  • 29
  • 5

2 Answers2

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.

Stephen Emery
  • 162
  • 1
  • 8
  • 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 Jan 16 '20 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? – Stephen Emery Jan 16 '20 at 17:55
  • I checked it again. The black one is apparently on my cell phone. Thanks! – Luca Jan 16 '20 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);
    }
}
Dreamer
  • 517
  • 1
  • 4
  • 11