Full Screen without navigation & status bars
Asked Answered
F

6

15

I want to create a activity with full screen. Nothing on above like Notification Bar and nothing below like Home-Button etc.I am able to get this, but also wanted to remove below home-button bar:

enter image description here

This is my code.

    <style name="MyScreen" parent="@style/Theme.AppCompat.Light">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>
Fogbound answered 13/4, 2017 at 10:16 Comment(0)
A
25

What you need is called Immersive Full-Screen Mode.

enter image description here

// This snippet hides the system bars.
private void hideSystemUI() {
    // Set the IMMERSIVE flag.
    // Set the content to appear under the system bars so that the content
    // doesn't resize when the system bars hide and show.
    mDecorView.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 // hide nav bar
            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
            | View.SYSTEM_UI_FLAG_IMMERSIVE);
}

// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
    mDecorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
Amphibious answered 13/4, 2017 at 10:21 Comment(2)
Add View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY if you want to hide bars automatically after some time.Edgerton
This is deprecated. You can use stackoverflow.com/a/64828067 instead.Rhapsody
S
4

/** * Hide both the navigation bar and the status bar. */

public void hideStatusBar() {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        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
                );
    }
}
Sieber answered 6/7, 2019 at 12:44 Comment(0)
U
2

If there are still spaces for the system bar and navigation bar even under immersive mode. Make sure the splash imageView is not in a FrameLayout that insets it. If it is do this i.e. set android:fitsSystemWindows = "false"

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false">
Unsex answered 21/3, 2018 at 10:3 Comment(0)
E
1

This piece of code worked for me on 5.1

    View mDecorView = activity.getWindow().getDecorView();
    mDecorView.setSystemUiVisibility(View.GONE);
Entrant answered 29/5, 2018 at 1:17 Comment(0)
C
1

If you use viewBinding functionality in your project you can do it like that in Fragment(didn't check Activity):

private fun hideSystemUI() {
    binding.root.systemUiVisibility = (
        View.SYSTEM_UI_FLAG_IMMERSIVE
            or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            or View.SYSTEM_UI_FLAG_FULLSCREEN
        )
}

This code also prevents your bottom bar to jump up, after you navigate from this fragment to previous and your main activity has bottom bar.

Concerning answered 15/7, 2021 at 14:32 Comment(1)
It's now mostly deprecated but it helped me get started.Amalea
T
-3

Do it programmatically in your activity class:

public class ActivityMain extends AppCompatActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // this will remove title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main);
    }
}
Termination answered 13/4, 2017 at 10:24 Comment(2)
Thanks man. But i choose Immersive Full Screen approach to get my desired results.Fogbound
Oh yeah. Mistaken.Termination

© 2022 - 2024 — McMap. All rights reserved.