1. 首先在res\values\下新建一个名为colors.xml的文件,内容如下:
2 |
< drawable name = "dark_gray" >#8F8F8F</ drawable > |
3 |
< drawable name = "light_gray" >#EEEEEE</ drawable > |
4 |
< drawable name = "white" >#FFFFFF</ drawable > |
5 |
< drawable name = "black" >#000000</ drawable > |
6 |
< drawable name = "blue" >#2A00FF</ drawable > |
7 |
< drawable name = "green" >#f0f0</ drawable > |
8 |
< drawable name = "yellow" >#FFFEA4</ drawable > |
2. 在res\drawable\下新建一个名为text_selector.xml的文件,内容如下:
1 |
<? xml version = "1.0" encoding = "UTF-8" ?> |
3 |
< item android:state_selected = "true" android:color = "@drawable/white" /> |
4 |
< item android:state_pressed = "true" android:color = "@drawable/white" /> |
5 |
< item android:color = "@drawable/black" /> |
3. 给你的button对象添加一个属性,内容如下:
1 |
android:textColor="@drawable/text_selector" |
这样你的按钮不光背景可以变化,颜色也可以变化(本例子未点击时为黑色,点击后为白色),希望能对你有用。