Android自定义Button字体颜色
2012-03-23 14:17
260 查看
http://www.2cto.com/kf/201111/109799.html
我们可以使用selector来实现Button的特效,如图所示:
![](http://www.2cto.com/uploadfile/2011/1101/20111101035218191.png)
默认情况
![](http://www.2cto.com/uploadfile/2011/1101/20111101035219674.png)
获得焦点的时候
![](http://www.2cto.com/uploadfile/2011/1101/20111101035219824.png)
点击按钮
main.xml
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="按下或者获得焦点Button会变不同颜色"
<SPAN style="COLOR: #ff0000">android:textColor="@color/button_text" </SPAN>/>
</LinearLayout>
www.2cto.com
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="按下或者获得焦点Button会变不同颜色"
android:textColor="@color/button_text" />
</LinearLayout>
XML 文件保存在res/color/button_text.xml
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:color="#ffff0000"/> <!-- pressed -->
<item android:state_focused="true" android:color="#ff0000ff"/> <!-- focused -->
<item android:color="#ff000000"/> <!-- default -->
</selector>
我们可以使用selector来实现Button的特效,如图所示:
![](http://www.2cto.com/uploadfile/2011/1101/20111101035218191.png)
默认情况
![](http://www.2cto.com/uploadfile/2011/1101/20111101035219674.png)
获得焦点的时候
![](http://www.2cto.com/uploadfile/2011/1101/20111101035219824.png)
点击按钮
main.xml
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="按下或者获得焦点Button会变不同颜色"
<SPAN style="COLOR: #ff0000">android:textColor="@color/button_text" </SPAN>/>
</LinearLayout>
www.2cto.com
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="按下或者获得焦点Button会变不同颜色"
android:textColor="@color/button_text" />
</LinearLayout>
XML 文件保存在res/color/button_text.xml
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:color="#ffff0000"/> <!-- pressed -->
<item android:state_focused="true" android:color="#ff0000ff"/> <!-- focused -->
<item android:color="#ff000000"/> <!-- default -->
</selector>
相关文章推荐
- Android自定义Button字体颜色和背景颜色
- Android自定义Button字体颜色
- Android之自定义背景Button按钮、自定义形状Button的全攻略、设置字体颜色
- Android自定义Button的背景和字体样式
- Android 通过继承TextView类自定义字体默认颜色
- android 代码设置Button字体颜色
- Android 自定义Notification字体颜色适配
- Android自定义ActionBar背景色、字体颜色等样式style
- Android 自定义Spinner字体、颜色、大小
- Android自定义TextView边框颜色(动态改变边框颜色以及字体颜色)
- android自定义键盘(解决弹出提示的字体颜色问题)
- VS MONO Android开发控件悬浮显示提醒 自定义背景颜色、字体、数字颜色、摆放位置
- Android 自定义 spinner (背景、字体颜色)
- Android自定义PreferenceCategory的title颜色、字体大小写的方法
- Android 自定义 spinner (背景、字体颜色)
- android 自定义 4.0的spinner 自定义spinner的字体和颜色
- Android Button按钮点击变换字体颜色
- Android 自定义Notification字体颜色适配
- Android 自定义 spinner (背景、字体颜色)
- Android中的Button自定义点击效果之改变点击时按钮的颜色