美文网首页
Textview设置图片,以及自定样式

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

作者: 追逐未来2016 | 来源:发表于2017-10-16 11:28 被阅读0次

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>

相关文章

网友评论

      本文标题:Textview设置图片,以及自定样式

      本文链接:https://www.haomeiwen.com/subject/bulkuxtx.html