展会信息港展会大全

Android自定义Button字体颜色
来源:互联网   发布日期:2015-12-08 16:47:29   浏览:1640次  

导读:我们可以使用selector来实现Button的特效,如图所示: 默认情况 获得焦点的时候 点击按钮 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 an...

我们可以使用selector来实现Button的特效,如图所示:

默认情况

获得焦点的时候

点击按钮

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>

作者hkp2008

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港