Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: using image instead of text on a button

I've been working on my android calculator and i can't seem to insert an image instead of text on a button. For example sqrt I don't want to have sqrt written on my button i want the image of the symbol on it, the same goes for x^y and alot of others. I have my custom background of the button working just fine. Thank you for your help in advance :)

EDIT: Thats not what i wanted i did manage to get my custom button and thats fine. On my button since its a calculator button i have android:text on it saying sqrt. I want to remove that and insert another png on my button showing the symbol of the square root instead of that text. Thank you for quick responses.

like image 993
user1755934 Avatar asked Oct 18 '12 10:10

user1755934


2 Answers

<Button 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:drawableTop="@drawable/imageName"/>

You can have both text and image (or no text) when using the attribute drawableTop, drawableBottom, drawableLeft and drawableRight.

And for positioning the image how you want, consider using: paddingTop, paddingBottom, paddingLeft and paddingRight.

like image 169
Carnal Avatar answered Nov 14 '22 21:11

Carnal


You can do this by ImageButton:

        <ImageButton
            android:id="@+id/submitEmailButton"
            android:layout_height="wrap_content" android:layout_width="wrap_content"
            android:layout_gravity="right" android:layout_marginRight="15dip"
            android:background="@drawable/ic_submit" />

Here ic_submit is the image you want to show as a button.

like image 34
Yogesh Somani Avatar answered Nov 14 '22 23:11

Yogesh Somani