按下时更改按钮的文字颜色 [英] change button text color when pressed
问题描述
我已将按钮设为透明,因此我希望在按下按钮时更改按钮文本的颜色.是否可以仅使用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屋!