I'm trying to adjust the padding in a Button so when the user presses the button the text shifts downward to help visually indicate a press was made.
styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Img_Button">
<item name="android:layout_width">@dimen/img_button_width</item>
<item name="android:layout_height">@dimen/img_button_height</item>
<item name="android:layout_marginTop">@dimen/img_button_marginTop</item>
<item name="android:layout_marginBottom">@dimen/img_button_marginTop</item>
<item name="android:paddingTop">@drawable/button_padtop_states</item>
<item name="android:paddingBottom">@drawable/button_padbottom_states</item>
<item name="android:background">@drawable/button_img_states</item>
<item name="android:gravity">center</item>
<item name="android:textColor">@drawable/button_txt_states</item>
<item name="android:textSize">@dimen/img_button_text_size</item>
<item name="android:textStyle">bold</item>
</style>
For the text color I'm able to change color using a selector indicated in the style.xml file
button_txt_states.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="@color/green_med" />
<item android:state_pressed="true" android:color="@color/white" />
<item android:state_focused="true" android:color="@color/white" />
<item android:color="@color/white" />
</selector>
So those change the text color in the button depending upon the button's state. So what I'd like to accomplish is assigning different padding values that would make the text shift downward just a bit when the user presses the button to visually indicate a button press. I've created a selector file for the paddingTop and paddingBottom values in the style.xml file.
button_padtop_states.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:value="2dp" />
<item android:state_pressed="true" android:value="3dp" />
<item android:state_focused="true" android:value="2dp" />
<item android:value="2dp" />
</selector>
So everything compiles and I can start the app on a device, but crashes with
E/AndroidRuntime(19515): Caused by: java.lang.UnsupportedOperationException:
Can't convert to dimension: type=0x3
I understand it's crashing because there's no way to convert a "value" into a dimension. So now I'm wondering if there a way to adjust the button's padding using a selector and style, like color and drawables on a button?
Thanks.