How to create button with image & text

走远了吗. 提交于 2020-01-02 11:11:47

问题


Friends,

I want to display a button in android like mentioned in screenshot.

Could anyone guide me through how to achieve this?


回答1:


There is the ImageButton which you can use for that.

But I'm not sure how to make the Text on the button look like the Text in your screenshot. I would simply create the image with the text and then use it for the ImageButton.




回答2:


Use a normal Butto with drawableLeft attribute. See my sample code:

<Button android:layout_width="100dip" 
    android:layout_height="wrap_content"
    android:text="Refresh"
    android:drawableLeft="@drawable/ic_btn_refresh"
    android:id="@+id/btn_refresh" />



回答3:


You could use 9-patch fot background. You can specify padding area there (bottom and right lines), so background will be stretchable while text will not cover image. :)




回答4:


<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/refresh"
android:text="Refresh"/>


来源:https://stackoverflow.com/questions/6253488/how-to-create-button-with-image-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!