按下时更改按钮的文字颜色 [英] change button text color when pressed

查看:122
本文介绍了按下时更改按钮的文字颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将按钮设为透明,因此我希望在按下按钮时更改按钮文本的颜色.是否可以仅使用xml文件来执行此操作?

I have made my button transparent so I would like to have the button text color change when the button is pressed. Is it possible to do this using just xml files?

推荐答案

请参阅本文档中称为状态列表的部分...

See the section called State List in this bit of documentation...Drawable Resources.

您可以定义两个不同的Button xml文件,一个用于透明的默认"状态,另一个使用红色"按钮表示您的已按下"状态.然后,您定义一个selector,以在不同状态下切换可绘制资源.

You can define two different Button xml files one for the transparent 'default' state and another with the button as Red for your 'pressed' state. You then define a selector which switches the drawable resources in the different states.

根据devunwired的评论,颜色状态列表"资源可能更适合仅更改颜色,而不是可绘制对象本身.

As per devunwired's comment the Color State List resource is probably more suitable for just changing colours rather than the drawable itself.

这篇关于按下时更改按钮的文字颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆