2012-09-11

Android ImageButton with Text

Android ImageButton cannot add Text on it, you should use Button with drawable background instead.

<Button
    android:id="@+id/buttonok"
    android:layout_width=" wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/button_ok"
    android:background="@drawable/back_button_bg"
    android:text="@string/text_ok"
    android:paddingRight="5dp"
    android:textColor="@android:color/primary_text_dark"/>

You can put the drawable wherever you want by using: drawableTop, drawableBottom, drawableLeft or drawableRight.


For button background, you can define a drawable for display the pressed effect for this button.

back_button_bg.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_pressed="true"
        android:drawable="@drawable/ic_menu_back_selected" />
</selector>


No comments: