How to hide status bar in android in just one activity
Asked Answered
N

13

25

I want to hide status bar / notification bar in splash screen I am using style:<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> this dose not hide the status bar, how should i do this?

Noelnoelani answered 23/3, 2017 at 6:19 Comment(1)
Possible duplicate of How to hide status bar in AndroidAccession
E
87

If you want to remove status bar then use this before setContentView(layout) in onCreateView method

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

credits

Earmuff answered 23/3, 2017 at 6:23 Comment(3)
use getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) if you want to add it back.Natka
@Natka Thanks that helped a lotStrop
Damn, I was using it after setContentView(), haha, thanks manMildew
T
32

You can do something like below for appropriately setting theme on your particular activity -

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/launch_theme</item>
        <item name="android:windowTranslucentNavigation">false</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">true</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowDrawsSystemBarBackgrounds">false</item>
 </style>
Testee answered 21/12, 2018 at 9:6 Comment(2)
thanks man very good approach if you want to avoid hiding status bar animation after the view has been drawnHorney
The android:windowFullscreen is what is was looking for using in my styles.xml – it works wonderfully for me and the same as FLAG_FULLSCREEN for me!Marnimarnia
L
5

Try this:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowFullscreen">true</item>
</style>
Louvenialouver answered 15/9, 2020 at 4:24 Comment(0)
G
2

Use Below Code to solve your problem.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Add Below line to hide 
        getSupportActionBar().hide();
    }
Garratt answered 23/3, 2017 at 6:36 Comment(1)
this hides the ActionBar and if you are using style: <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> your app will crashEscamilla
B
2

Try this complete solution for backward below android version 16 and forward compatible solution

    if (Build.VERSION.SDK_INT < 16)
    {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    else
    {
        View decorView = getWindow().getDecorView();
        // Hide the status bar.
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
    }
Bharat answered 13/6, 2017 at 6:30 Comment(0)
T
2

For Kotlin users.

In styles.xml add new style:

<style name="NoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

Now in AndroidManifest.xml add newly created style:

 <activity
            android:name=".MainActivity"
            android:theme="@style/NoActionBarTheme"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustResize"

 >...</activity>

Finally in MainActivity.kt make following changes:

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        //Add below line to hide status bar
        window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
}

Now the status bar should be gone:

enter image description here

Touzle answered 20/5, 2020 at 9:38 Comment(0)
M
1

To make your activity fullscreen, add this code in onCreate before setContentView:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Matheson answered 23/3, 2017 at 6:23 Comment(0)
G
1

This is what I used and it worked perfectly.

Add this code to your activity onCreate before setContentView:

    @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);

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

    }
Gironde answered 8/3, 2019 at 19:59 Comment(0)
B
1

if you are using this in theme app

Theme.MaterialComponents.NoActionBar

change to

Theme.AppCompat.NoActionBar

and add code in activity:

fun fullScreen(activity: Activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
    if (activity.window.insetsController != null) {
        val insetsController = activity.window.insetsController
        if (insetsController != null) {
            insetsController.hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
            insetsController.systemBarsBehavior =
                WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
        }
    }
} else {
    activity.window.setFlags(
        WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
        WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
    )
}

}

Blasting answered 4/12, 2020 at 3:52 Comment(0)
H
1

If you want to hide status bar line and action bar, you have to change the line in themes.xml

   <style name="Theme.MyApp" 
           parent="Theme.MaterialComponents.DayNight.DarkActionBar">

to

   <style name="Theme.MyApp" 
            parent="Theme.MaterialComponents.DayNight.NoActionBar">

and this to activity class in which you don't want status bar line..

     requestWindowFeature(Window.FEATURE_NO_TITLE)
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
           WindowManager.LayoutParams.FLAG_FULLSCREEN);

Plz make sure that you have to add these lines above this in onCreate() method.

        setContentView(R.layout.activity_main)
Honeyhoneybee answered 8/12, 2021 at 7:58 Comment(0)
L
0

Try this:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
Lubricity answered 23/3, 2017 at 6:26 Comment(0)
M
0

I did some magic code. Buttons in the status bar can be clicked, but it's difficult. Part for 4.4 does not work well.

    /** Скрывает статус-бар */
    private void hideStatusBar(View decorView)
    {
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);

        android.app.ActionBar actionBar = getActionBar();

        if (actionBar != null)
            actionBar.hide();
    }

    @Override protected void onCreate(Bundle savedInstanceState)
    {
            super.onCreate(savedInstanceState);

            try
            {
                // for < 4.0
                if (Build.VERSION.SDK_INT < 16)
                    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
                // for > 4.0
                else
                {
                    final View decorView = getWindow().getDecorView();

                    hideStatusBar(decorView);

                    decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
                    {
                        @Override public void onSystemUiVisibilityChange(int visibility)
                        {
                            if (visibility != View.SYSTEM_UI_FLAG_FULLSCREEN)
                                hideStatusBar(decorView);
                        }
                    });
                }
            }
            catch (Throwable t)
            {
                Util.log("Ошибка при попытке свернуть статус бар");
                t.printStackTrace();
            }

            setContentView(R.layout.activity_main);
}
Message answered 20/6, 2018 at 9:58 Comment(0)
A
0

If you want to remove the status bar then

For Java

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

For Kotlin

    window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN

For flutter

    SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
Allaround answered 24/8, 2022 at 18:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.