Create a Button with an Image and Text [Android]

来源:互联网 发布:js canvas动画 编辑:程序博客网 时间:2024/05/18 00:18

The Android SDK docs aren’t very helpful. Period. More specifically, they aren’t clear on how to create a button with both an image and text. Allow me to help.

Place the following in your layout XML file, replacing [image] with your image:

<Button     android:id="@+id/groups_button_bg"     android:layout_height="wrap_content"     android:layout_width="wrap_content"     android:text="Groups"     android:drawableTop="@drawable/[image]" />

Using android:drawableTop="@drawable/...", we’re able to place an imageabove the button text. The following options are available for placing the image in different positions relative to the button text:

android:drawableLeftandroid:drawableRightandroid:drawableBottomandroid:drawableTop

In addition, android:drawablePadding can be used to specify the amount of padding between the image and button text.


原创粉丝点击