How to hide the status bar in android in just one asset

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

+12
source share
9 answers

If you want to delete the status bar, use it before setting setContentView (layout) in the onCreateView method

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

loans

+41
source

You can do something like below to properly set the theme for your specific 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>
+3
source

, .

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Add Below line to hide 
        getSupportActionBar().hide();
    }
+2

, onCreate setContentView:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
+1

Android 16

    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);
    }
+1

:

 @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);
    }
0

. , . 4.4 .

    /**  - */
    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);
}
0

, , .

onCreate 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);

}
0

@style/Theme.AppCompat.Light.NoActionBar .

<activity
    android:name=".Activity"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar">

</activity> 
-3

Source: https://habr.com/ru/post/1672978/


All Articles