xml中的textView:
<TextView
android:id="@+id/TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@drawable/checkmark"
android:gravity="center_vertical"
android:textStyle="bold"
android:textSize="24dip"
android:maxLines="1"
android:ellipsize="end"/>
代码中改变drawable:
Drawable drawable= getResources().getDrawable(R.drawable.drawable);
/// 这一步必须要做,否则不会显示.
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
myTextview.setCompoundDrawables(drawable,null,null,null);
DrawableRight、Bottom、Top同理。可参考这个函数:
public void setCompoundDrawablesWithIntrinsicBounds (Drawable left,
Drawable top, Drawable right, Drawable bottom)
本文详细介绍了如何在XML布局文件中使用TextView组件,并通过设置复合绘制来展示自定义图标,包括设置文本样式、大小、对齐方式及复合图标显示。
6147

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



