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 button. How do i do that/
I want to set the text because localization would be used in the project....
ImageButton can't have text (or, at least, android:text isn't listed in its attributes).
So fundamentally, a Button can have text and is clickable, whereas an ImageButton is a bit more flexible in how you set the image. It has methods from its ImageView base class like setImageURI which a Button does not.
I can get the text from a button: String buttonText = button. getText();
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With