Search code examples
androidandroid-button

change button text color when pressed


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?


Solution

  • 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.