安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom


Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_new);

//调用setCompoundDrawables时,必须调用Drawable.setBounds()方法,否则图片不显示

rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight());  // left, top, right, bottom
tvVersionStatus.setCompoundDrawables(null, null, rightDrawable, null);  // left, top, right, bottom

https://blog.csdn.net/catoop/article/details/39959175

<TextView android:id="@+id/tv_versionstatus"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawablePadding="5dp"
    android:drawableRight="@drawable/icon_new"
    android:text="版本"
    android:textColor="#363636"
    android:textSize="20sp" />


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM