android沉浸式 CoordinatorLayout+AppBarLayout+CollapsingToolbarLayout+Toolbar

實現(xiàn)效果


image.png

image.png

image.png

沉浸式實現(xiàn):


image.png

values-v19

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">

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

    </style>

</resources>

values-v21

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">

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

    </style>

</resources>

values-v23

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

        <item name="colorPrimary">@color/red_eb</item>
        <item name="colorPrimaryDark">@color/transparent</item>
        <item name="colorAccent">@color/red_eb</item>
        <item name="android:windowLightStatusBar">true</item>

    </style>

</resources>

布局layout的實現(xiàn)

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/dp_208">


        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            app:contentScrim="@color/white"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:background="@color/red_eb"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

            <androidx.appcompat.widget.Toolbar
                android:minHeight="@dimen/dp_48"
                app:layout_collapseMode="pin"
                app:layout_scrollFlags="scroll"
                android:layout_width="match_parent"
                android:layout_height="@dimen/dp_48"
                android:layout_marginTop="@dimen/dp_20">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:paddingRight="@dimen/dp_25"
                    android:text="標題"
                    android:textSize="@dimen/sp_18" />

            </androidx.appcompat.widget.Toolbar>

        </com.google.android.material.appbar.CollapsingToolbarLayout>

        <com.google.android.material.tabs.TabLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/dp_35">

            <com.google.android.material.tabs.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1111" />

            <com.google.android.material.tabs.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1111" />

            <com.google.android.material.tabs.TabItem
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1111" />

        </com.google.android.material.tabs.TabLayout>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/jin_fff"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市吱韭,隨后出現(xiàn)的幾起案子嗜傅,更是在濱河造成了極大的恐慌厨钻,老刑警劉巖磷醋,帶你破解...
    沈念sama閱讀 222,807評論 6 518
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件淤井,死亡現(xiàn)場離奇詭異滚局,居然都是意外死亡,警方通過查閱死者的電腦和手機乃秀,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,284評論 3 399
  • 文/潘曉璐 我一進店門肛著,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人环形,你說我怎么就攤上這事策泣⊙每” “怎么了抬吟?”我有些...
    開封第一講書人閱讀 169,589評論 0 363
  • 文/不壞的土叔 我叫張陵,是天一觀的道長统抬。 經(jīng)常有香客問我火本,道長,這世上最難降的妖魔是什么聪建? 我笑而不...
    開封第一講書人閱讀 60,188評論 1 300
  • 正文 為了忘掉前任钙畔,我火速辦了婚禮,結果婚禮上金麸,老公的妹妹穿的比我還像新娘擎析。我一直安慰自己,他們只是感情好挥下,可當我...
    茶點故事閱讀 69,185評論 6 398
  • 文/花漫 我一把揭開白布揍魂。 她就那樣靜靜地躺著,像睡著了一般棚瘟。 火紅的嫁衣襯著肌膚如雪现斋。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,785評論 1 314
  • 那天偎蘸,我揣著相機與錄音庄蹋,去河邊找鬼。 笑死迷雪,一個胖子當著我的面吹牛限书,可吹牛的內容都是我干的。 我是一名探鬼主播章咧,決...
    沈念sama閱讀 41,220評論 3 423
  • 文/蒼蘭香墨 我猛地睜開眼倦西,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了慧邮?” 一聲冷哼從身側響起调限,我...
    開封第一講書人閱讀 40,167評論 0 277
  • 序言:老撾萬榮一對情侶失蹤舟陆,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后耻矮,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體秦躯,經(jīng)...
    沈念sama閱讀 46,698評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 38,767評論 3 343
  • 正文 我和宋清朗相戀三年裆装,在試婚紗的時候發(fā)現(xiàn)自己被綠了踱承。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,912評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡哨免,死狀恐怖茎活,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情琢唾,我是刑警寧澤载荔,帶...
    沈念sama閱讀 36,572評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站采桃,受9級特大地震影響懒熙,放射性物質發(fā)生泄漏。R本人自食惡果不足惜普办,卻給世界環(huán)境...
    茶點故事閱讀 42,254評論 3 336
  • 文/蒙蒙 一工扎、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧衔蹲,春花似錦肢娘、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,746評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至贞远,卻和暖如春畴博,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背蓝仲。 一陣腳步聲響...
    開封第一講書人閱讀 33,859評論 1 274
  • 我被黑心中介騙來泰國打工俱病, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人袱结。 一個月前我還...
    沈念sama閱讀 49,359評論 3 379
  • 正文 我出身青樓亮隙,卻偏偏與公主長得像,于是被迫代替她去往敵國和親垢夹。 傳聞我的和親對象是個殘疾皇子溢吻,可洞房花燭夜當晚...
    茶點故事閱讀 45,922評論 2 361