change button text color when pressed

后端 未结 5 1271
情歌与酒
情歌与酒 2021-02-02 15:53

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?

5条回答
  •  春和景丽
    2021-02-02 16:31

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

    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.

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

提交回复
热议问题