美文网首页帮助类
在代码中为TextView添加icon

在代码中为TextView添加icon

作者: 根艮哏艮根 | 来源:发表于2017-10-17 14:45 被阅读5次

在xml中设置TextView的icon

 <TextView
                android:id="@+id/tv_type"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:drawableLeft="@mipmap/notice"
                android:drawablePadding="5dp"
              />

在代码中设置TextView的icon

      Drawable drawable =context.getResources().getDrawable(R.mipmap.notice_g);
      drawable.setBounds(0, 0, drawable.getMinimumWidth(),drawable.getMinimumHeight());
        //设置左侧的图标
      mTextView.setCompoundDrawables(drawable, null, null, null);

相关文章

网友评论

    本文标题:在代码中为TextView添加icon

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