How to hide status bar in android in just one activity

点点圈 提交于 2020-05-10 07:28:07

问题


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?


回答1:


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




回答2:


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>



回答3:


Use Below Code to solve your problem.

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



回答4:


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



回答5:


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



回答6:


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



回答7:


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



回答8:


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

    }


来源:https://stackoverflow.com/questions/42968600/how-to-hide-status-bar-in-android-in-just-one-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!