Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set text of Image Button (Android)?

Tags:

java

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 button. How do i do that/

I want to set the text because localization would be used in the project....

like image 879
Rohan K Avatar asked Aug 31 '10 12:08

Rohan K


People also ask

Can image button have text?

ImageButton can't have text (or, at least, android:text isn't listed in its attributes).

What is difference between Button and image button?

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.

How do I fetch a text button?

I can get the text from a button: String buttonText = button. getText();


1 Answers

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?

like image 164
Maragues Avatar answered Oct 14 '22 13:10

Maragues