Apply Different Style to Button When Pressed

user440308 picture user440308 · Sep 16, 2010 · Viewed 26k times · Source

Is there a way to apply a style to a button when the button is pressed?

If I have a style in style.xml:

<resources>
    <style name="test">
        <item name="android:textStyle">bold</item>
    </style>
</resources>

a selector in button.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/test_pressed"
              style="@style/test"
          android:state_pressed="true"/>
    <item android:drawable="@drawable/test_focused"
          android:state_focused="true"/>
    <item android:drawable="@drawable/test_normal"/>
</selector>

then how would I reference button.xml in my layout?

<Button
        ...
        android:???="button"/>

Thanks!

Answer

esilver picture esilver · Oct 9, 2011

Romain Guy suggests it is not possible:

http://code.google.com/p/android/issues/detail?id=8941

"Selector works only for drawables, not text appearances. There is currently not plan to make this happen."