Textview设置图片,以及自定样式

1.设置图片

Drawable dra= activity.getResources().getDrawable(R.drawable.open_remind_icon);
//必须设置宽高, 否则无法显示
dra.setBounds( 0, 0, dra.getMinimumWidth(),dra.getMinimumHeight());
textview.setCompoundDrawables(dra, null, null, null);
//文字和图片的间距
textview.setCompoundDrawablePadding(PhoneUtil.dip2px(activity,6));

2.清除图片

textview.setCompoundDrawables(null, null, null, null);
  1. shape
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle"> //形状
    //填充颜色
    <solid android:color="@color/white" />
    //圆角
    <corners android:radius="3px" />
    //内部间距
    <padding android:top="5dp"
             android:bottom="5dp"
             android:left="9dp"
             android:right="9dp"/>
    //边框颜色和宽度
    <stroke android:color="@color/bg_ee2532"
            android:width="1px"/>

</shape>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容