首页 > 移动平台 > 详细

Android:Textview 通过代码设置 Drawable

时间:2016-11-22 12:51:08      阅读:353      评论:0      收藏:0      [点我收藏+]

解决方案

public void  setCompoundDrawables  (Drawable left, Drawable top, Drawable right, Drawable bottom);  

类似与在 XML 中

android:drawableLeft="@drawable/icon"  

 

使用 TextView 直接调用 setCompoundDrawables() 就可以实现添加 drawable,但是添加完成以后无法显示,查看源码,发现有这么一句话

The Drawables must already have had {@link Drawable#setBounds} called.

1 Drawable drawable = context.getResources().getDrawable(R.drawable
2                         .todo_date_alert_2x);
3 drawable.setBounds(0,0,drawable.getMinimumWidth(),drawable.getMinimumHeight());
4 holder.todoDataALLDate.setCompoundDrawables(drawable, null, null, null);

 

Android:Textview 通过代码设置 Drawable

原文:http://www.cnblogs.com/liyiran/p/6088437.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!