How to add image(left) and text on button

时间秒杀一切 提交于 2019-12-02 22:12:48
Michael Shrestha

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 );

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);
        android:text="Documentos"
        android:drawableLeft= "@drawable/ic_document"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!