AppBar won't overlap statusbar, when using CollapsingToolbarLayout

非 Y 不嫁゛ 提交于 2019-12-11 05:26:50

问题


I want AppBar to overlap StatusBar. AppBar has image as background and I want this image to overlap statusbar, but when I use CollapsingToolbarLayout StatusBar gets white and image is below StatusBar:

I want something like this:

Heres my code:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="218dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true"
        >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/main.collapsing"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleMarginEnd="64dp"
            app:titleEnabled="false"
            >

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"
                android:src="@mipmap/mount"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin"
                />

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

    </android.support.v4.widget.NestedScrollView>

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

回答1:


Take a folder and set the theme..

Main theme In values/styles.xml

 <resources>


    <style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorControlHighlight">@color/accent_translucent</item>
    <item name="colorAccent">@color/accent</item>


    </style>

</resources>

res/values-v21/styles.xml

  <resources>

       <style name="AppTheme" parent="BaseTheme">

       <item name="android:colorControlHighlight">@color/accent_translucent</item>


       <item name="android:windowSharedElementsUseOverlay">false</item>


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

       </style>

       </resources>

Note: If you are using android:windowTranslucentStatus ... Remove it From themeor set false

  <item name="android:windowTranslucentStatus">true</item>

Example shown here By this I am Remove this part and get result

Follow the Example For your requirement fulfillment

https://github.com/antoniolg/MaterializeYourApp

Like that result



来源:https://stackoverflow.com/questions/39225380/appbar-wont-overlap-statusbar-when-using-collapsingtoolbarlayout

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