我在應用程序中看到過這個。Android:如何使appbar像這樣?
正如你所看到的,appbar是半透明的,它不是一個大問題,但向下滾動頁面,它開始亮點越來越多,直到它完全變成非trasparent appbar,這樣的事情:
問:我怎樣才能讓這樣的事情?
我在應用程序中看到過這個。Android:如何使appbar像這樣?
正如你所看到的,appbar是半透明的,它不是一個大問題,但向下滾動頁面,它開始亮點越來越多,直到它完全變成非trasparent appbar,這樣的事情:
問:我怎樣才能讓這樣的事情?
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/cor_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="192dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapseToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/image_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/event_image"
android:scaleType="fitXY"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.6" />
<android.support.v7.widget.Toolbar
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
android:theme="@style/MyCustomToolbarTheme"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/ic_person_add_white_24dp"
app:backgroundTint="@android:color/holo_blue_dark"
app:borderWidth="0dp"
app:elevation="6dp"
app:fabSize="normal"
app:pressedTranslationZ="12dp"
app:rippleColor="?attr/colorControlHighlight" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
謝謝對於答覆,我嘗試了代碼,但我得到了這些錯誤:錯誤:(15)找不到屬性'contentScrim'包''中的資源標識符 錯誤:(1) 5)任何資源標識符在包「找到的屬性「expandedTitleMarginEnd」」 錯誤:(15)未發現屬性資源標識符「expandedTitleMarginStart」在包「」 錯誤:(15)否在找到的屬性「layout_scrollFlags」資源標識符包「」 錯誤:(25)未發現屬性資源標識符「」在包「」 – navidjons
編譯「com.android.support:appcompat-v7:23.0.1」 編譯「com.android.support:design layout_collapseMode: 23.0.1' 編譯‘com.android.support:recyclerview-v7:23.0.1’ 編譯‘com.android.support:support-v4:23.0.1’你需要這些依賴添加到您的文件的gradle –
您提到的操作欄是摺疊的工具欄佈局,它當前通過使用android設計支持庫可用。這裏有一些關於如何在你的應用程序中實現它的指南。
Design Support Library (IV): Collapsing Toolbar Layout
Handling Scrolls with CoordinatorLayout
https://medium.com/@nullthemall/1-20f-behaviors-of-alpha-6f506c9cb6a7 –