首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

兑现背景渐变的方法

2012-08-27 
实现背景渐变的方法经过几天的摸索,终于找到不使用图片实现背景渐变的方法首先建立文件drawable/shape.xml

实现背景渐变的方法
经过几天的摸索,终于找到不使用图片实现背景渐变的方法

首先建立文件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">
该方法同样适用于控件

热点排行