简体   繁体   中英

How to make Statusbar not transparent(Android 5)

I'm using a CoordinatorLayout and this( app:layout_scrollFlags="scroll|enterAlways" ) line of code in order the hide the toolbar whenever a RecyclerView is scrolled. And this also works pretty well, but the Toolbar does not get hidden behind the Statusbar because it is transparent.

My layout looks like this

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.yannisbecker.backup.MainActivity">

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|enterAlways" />

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

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

<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_backup_white_24dp"/>

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

Since I already searched up the internet and only found a lot of things about "How to make the Statusbar transparent" I'm now asking here and hope somebody can help me.

Because I don't have enought reputation, yet, you can find an image the shows my Problem here

If you want to hide the toolbar under the status bar when recycler-view is scrolled, then you've to change the color of the status-bar to your liking and also remove this attribute: android:fitsSystemWindows="true" from the <CoordinatorLayout> tag.

Setting the color of the status bar can be done in the MainActivity by using getWindow.setStatusBarColor() method :

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    getWindow().setStatusBarColor(getResources().getColor(R.color.primary_dark));
   }

or

Add or edit, if present, this tag in the styles.xml file in AppTheme.NoActionBar style

<item name="android:statusBarColor">@android:color/color_of_your_choice</item>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM