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?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Yes, you can do it like that:
layout/main_layout.xml:
color/button_text_color.xml:
You must set
@drawable
xml resource intextColor
attributteHere is example: Android customized button; changing text color
You have to do it in your code. Try this:
Declare:
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 aselector
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.
I like the solution proposed by Konstantin Burov in the other issue: Android customized button; changing text color
You can actually manage more states than just pressed and normal. But it should solve the problem.
Then you can use that selector drawable in your button changing the text color attribute like below. Note that the selector in the example below is named "button_text_color"
Using the same drawable approach you can also solve the background color of the button. Just remember that in the selector instead of using the "android:color" attribute you need to use the "android:drawable" attribute like below.
And then in the button itself do, note that this time the selector name is "button_background"