经过几天的摸索,终于找到不使用图片实现背景渐变的方法
首先建立文件drawable/shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#FFFFFFFF" android:endColor="#FFFF0000"
android:angle="270"/>
</shape>
在该文件中设置渐变的开始颜色(startColor)、结束颜色(endColor)和角度(angle)
接着创建一个主题values/style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="NewTheme" parent="android:Theme">
<item name="android:background">@drawable/shape</item>
</style>
</resources>
然后在AndroidManifest.xml文件中的application或activity中引入该主题,如:
<activity android:name=".ShapeDemo" android:theme="@style/NewTheme">
该方法同样适用于控件
首先建立文件drawable/shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#FFFFFFFF" android:endColor="#FFFF0000"
android:angle="270"/>
</shape>
在该文件中设置渐变的开始颜色(startColor)、结束颜色(endColor)和角度(angle)
接着创建一个主题values/style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="NewTheme" parent="android:Theme">
<item name="android:background">@drawable/shape</item>
</style>
</resources>
然后在AndroidManifest.xml文件中的application或activity中引入该主题,如:
<activity android:name=".ShapeDemo" android:theme="@style/NewTheme">
该方法同样适用于控件