Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change button text using <selector>

Tags:

android

I am using selector to change color of button. And I was trying to do same with text property. Is it possible to change text in such way?

like image 973
userbb Avatar asked Apr 27 '13 10:04

userbb


1 Answers

As far as I know, you can't do that because android:text="" takes string or string resource id as param. If you for example do something like this :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:state_pressed="false" android:text="SECOND" />
    <item android:state_focused="true" android:state_pressed="true" android:text="SECOND" />
    <item android:state_focused="false" android:state_pressed="true" android:text="SECOND" />
    <item android:text="FIRST" />
</selector>

, like the way we are changing text color or background, it will put the path to this selector as your button text. It will be something like : res/drawable/text_selector.xml or whenever you put this file.

So the only way to achieve this is to control it manually in button's OnClickListener.

like image 154
hardartcore Avatar answered Oct 22 '22 15:10

hardartcore