Android:Textview 通過代碼設置 Drawable


解決方案

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);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM