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

2017-10-16  本文已影响0人  追逐未来2016

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>
上一篇 下一篇

猜你喜欢

热点阅读