How to add image(left) and text on button

喜夏-厌秋 提交于 2019-12-20 10:24:23

问题


How to add image(left) and text on button?


For illustration:


回答1:


use android:drawableLeft="@drawable/image" in your layout xml

you can also do this from code

Drawable icon= getContext().getResources().getDrawable( R.drawable.image);
button.setCompoundDrawablesWithIntrinsicBounds( icon, null, null, null );



回答2:


We can also manage the size of drawable while doing programmatically

Drawable dr = getResources().getDrawable(R.drawable.mag_green);
dr.setBounds(0, 0, 43, 40); //Left,Top,Right,Bottom
search_bar.setCompoundDrawables(dr, null , null , null);



回答3:


        android:text="Documentos"
        android:drawableLeft= "@drawable/ic_document"


来源:https://stackoverflow.com/questions/17258386/how-to-add-imageleft-and-text-on-button

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