Android 开发中设置静态设置背景颜色
1.在res/下新建XML文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#FF0000</color>
<color name="green">#00FF00</color>
<color name="blue">#0000FF</color>
</resources>
2.在View控件中调用color标签
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="确定"
android:background="@color/red"/>
</RelativeLayout>
注:@color/是调用res/下的匹配的color标签
也可以将color标签嵌入到selector的item标签中使用
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="@color/red"/>
<item android:color="@color/green" />
</selector>