Hide and show statusBar with Toolbar at the same time in android

徘徊边缘 提交于 2019-12-11 05:53:18

问题


I know this question asked many time and I tested solutions which provide but none of them works. I want to hide StatusBar and Toolbar so I use following code to hide statusBar base on documentation:

 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;

 getWindow().getDecorView().setSystemUiVisibility(flags);

And this code for showing statusBar:

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);

It's works but When I hide statusBar my darkPrimaryColor is still visible like following pic (I use fade Animation with Translate for hiding Toolbar)

I also set fit android:fitsSystemWindows="false" But in this case oolbar goes behind statusBar.

I also see this thread but solution not work because I'm using drawerLayout as root.

Here is my layout:

 <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        tools:openDrawer="start">

        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/root">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/appbar">

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar" />

            </android.support.design.widget.AppBarLayout>

            <include layout="@layout/view_epg_player" />

        </android.support.design.widget.CoordinatorLayout>
    <android.support.v4.widget.DrawerLayout/>

Also try following code which green status-bar are disappear But it's not smooth and still looking for better approach, without causing a layout jerk.

Hide status-bar:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

Show status-bar

 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

来源:https://stackoverflow.com/questions/38189152/hide-and-show-statusbar-with-toolbar-at-the-same-time-in-android

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