How to set text of Image Button (Android)?
In my Android project, I've a image button whose background is set to some image. I want so set some text on the image 开发者_JS百科button. How do i do that/
I want to set the text because localization would be used in the project....
An ImageButton is not supposed to have text, that's why it's called ImageButton.
Try to use Button, which inherits from TextView and does have the android:text attribute.
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="mail"
android:background="@drawable/btn_selector"/>
Is there any particular reason why you want to use ImageButton over Button?
Rather than using the ImageButton, just use a regular button and use the drawable attributes. There are several depending on where you want the drawable to be.
http://developer.android.com/reference/android/widget/TextView.html#attr_android:drawableBottom
I was having the same problem. I have solved this by adding a TextView under the ImageButton and set its Text. If you used Button instead and tried to set your picture as a background, you will find out the Text in the middle of the picture and will not be obvious. But, in this way you will have the shape of Windows Icon above the file name.
精彩评论