我以这种方式实现了一个着色器,xml文件名为horde_shader.xml,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:endColor="@color/bordeaux"
android:angle="270">
</gradient>
</shape>
我还在相关的style.xml文件中实现了以下主题:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:endColor="@color/bordeaux"
android:angle="270">
</gradient>
</shape>
我尝试了以这种方式设置背景的活动:
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AllyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/royalBlue</item>
<item name="colorAccent">@color/royalBlue</item>
<item name="android:navigationBarColor">@color/royalBlue</item>
<item name="colorShader">@drawable/ally_shader</item>
<item name="imageFaction">@drawable/ally</item>
<item name="android:textColorSecondary">@android:color/white</item>
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:textColorHint">@android:color/white</item>
<item name="android:fontFamily">serif</item>
</style>
<style name="HordeTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/bordeaux</item>
<item name="colorAccent">@color/bordeaux</item>
<item name="android:navigationBarColor">@color/bordeaux</item>
<item name="colorShader">@drawable/horde_shader</item>
<item name="imageFaction">@drawable/horde1</item>
<item name="android:textColorSecondary">@android:color/white</item>
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:fontFamily">serif</item>
</style>
<style name="Theme">Theme</style>
<style name="AppTheme">AppTheme</style>
</resources>