简体   繁体   中英

How to implement collapsing toolbar with no toolbar

https://github.com/codepath/android_guides/wiki/Using-the-App-ToolBar

https://github.com/chrisbanes/cheesesquare

I saw an example, I've implemented a toolbar.

Toolbar for example, works as follows.

1) Expanded

在此处输入图片说明

2) Collapsed

在此处输入图片说明

But, I want to show the background, or the toolbar is transparent when the toolbar is collapsed. How can I implement the following? Like this...

在此处输入图片说明

To ensure that the background is transparent when the toolbar is collapsed make sure that the contentScrim is not set to transparent.

Here is an example of wht your layout might look like.

<android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="@android:color/transparent">

Add this to your Collapsing Layout in your layouts,

app:contentScrim="@android:color/transparent"

Example

 <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="@android:color/transparent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

To get a transparent background through layout XML use:

app:contentScrim="@android:color/transparent"

To do it programmatically:

collapsingToolbar.setContentScrimColor(Color.TRANSPARENT);
collapsingToolbar.setStatusBarScrimColor(Color.TRANSPARENT);

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