Android 漸變色沉浸式狀態欄

效果圖在最下

在AndroidManifest.xml中的activity中使用自定義主題
<activity android:name=".dailyAccompany.view.activity.AlarmListActivity"
    android:theme="@style/MyStatusBarTheme"
    android:screenOrientation="portrait">
</activity>

然後在style.xml中去定義該主題

<style name="MyStatusBarTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:windowTranslucentStatus">true</item>
    <!-- 設置statusBarColor 爲透明-->
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

在佈局文件中的第一個控件設置爲漸變

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/alarm_shade_bg"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <ImageView
        android:id="@+id/alarm_top"
        android:layout_width="match_parent"
        android:layout_height="64dp"
        android:background="@drawable/title_shade_bule"/>

       省略中間佈局。。。。。。。。。。。。。。。。。。

</android.support.constraint.ConstraintLayout>

然後去定義漸變佈局title_shade_bule

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="180"
        android:centerColor="#2798f0"
        android:endColor="#6043ce"
        android:startColor="#6043ce"
        android:type="linear" />
</shape>
就可以實現了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章