7

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.

4

5 回答 5

6
<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.

于 2012-10-18T10:32:41.383 回答
1

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.

于 2012-10-18T10:29:37.293 回答
0

I used this tutorial and it worked perfectly for me: http://www.mkyong.com/android/android-imagebutton-selector-example/

I haven't seen your code but basically you should remove the "text" tag from your xml and it should appear the image without text then.

I don't know if that's exactly what you were looking for or not, but I reccomend you to follow the tutorial and for sure it will work for you ;)

于 2012-10-18T10:30:17.690 回答
0

There are a number of alternatives you can try to implement to build your SQRT button:

  • draw the button as a 9-patch drawable so your SQRT symbol won't get distorted;
  • use a RelativeLayout with a button inside and implement a selector
于 2012-10-18T10:34:07.013 回答
0

You can simply set background for the Button and keep its text blank.

于 2012-10-18T12:11:26.163 回答