效果图在最下
在AndroidManifest.xml中的activity中使用自定义主题
android:theme="@style/TranslucentStatusTheme"
android:screenOrientation="portrait">
然后在style.xml中去定义该主题
要在三个不同的styles.xml文件中定义以适应不同安卓版本
values的styles.xml
values-v19的styles.xml
true
true
values-v21的styles.xml
false
true
@android:color/transparent
在布局文件中的第一个控件设置为渐变
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">
android:id="@+id/alarm_top"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="@drawable/title_shade_bule"/>
省略中间布局。。。。。。。。。。。。。。。。。。
然后去定义渐变布局title_shade_bule
android:shape="rectangle">
android:angle="180"
android:centerColor="#2798f0"
android:endColor="#6043ce"
android:startColor="#6043ce"
android:type="linear" />
就可以实现了
注:如果顶部是使用Toolbar,需要在Toolbar中加上
android:fitsSystemWindows="true"
以防止Toolbar与状态栏重叠
效果图:
20181229171916445.png