<TextView
android:id="@+id/bind_card_tv2"
style="@style/widget_weightW_w"
android:background="@null"
android:drawableLeft="@null"
android:drawablePadding="10dp"
android:textColor="@color/widget_black"
android:textSize="@dimen/text_15" />
设置drawableLeft
Drawable drawable= getResources().getDrawable(R.drawable.drawable);
/// 这一步必须要做,否则不会显示.
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
myTextview.setCompoundDrawables(drawable,null,null,null);
设置drawableRight
<pre name="code" class="java">titleTv.setCompoundDrawables(null, null, drawable, null);//画在右边
本文介绍了如何在Android中为TextView设置左侧和右侧图标的方法。通过使用Drawable资源并设置bounds,可以将图标放置在TextView的不同位置。这对于美化界面和提高用户体验非常有用。
1809

被折叠的 条评论
为什么被折叠?



