如何在代码中更改textView在xml文件中设置好的drawable对象
2013-06-09 11:06
417 查看
xml中的textView:
如程序中所见我在xml中设置了 DrawableLeft。
我想在代码中改变drawable。
有什么方法可以使用代码为textview设置drawableLeft呢?
回答:
public void setCompoundDrawables (Drawable
left, Drawable top, Drawable right, Drawable bottom);
类似调用方法如下:
也或参考另一个函数
public void setCompoundDrawablesWithIntrinsicBounds (Drawable left,
Drawable top, Drawable right, Drawable bottom)
<TextView android:id="@+id/bookTitle" 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"/>
如程序中所见我在xml中设置了 DrawableLeft。
我想在代码中改变drawable。
有什么方法可以使用代码为textview设置drawableLeft呢?
回答:
public void setCompoundDrawables (Drawable
left, Drawable top, Drawable right, Drawable bottom);
类似调用方法如下:
1.在XML中使用 android:drawableLeft="@drawable/icon" 2.代码中动态变化 Drawable drawable= getResources().getDrawable(R.drawable.drawable); /// 这一步必须要做,否则不会显示. drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); myTextview.setCompoundDrawables(drawable,null,null,null);
也或参考另一个函数
public void setCompoundDrawablesWithIntrinsicBounds (Drawable left,
Drawable top, Drawable right, Drawable bottom)
相关文章推荐
- 如何在代码中设置textView跑马灯效果(不是在xml中)
- 在代码中将TextView的文字颜色改为自己写的color.xml文件设置的颜色
- 如何在代码中动态为TextView/Button设置drawableRight
- Android 自定义view-如何设置TextView drawableLeft 图片大小?
- 如何在xml中设置textview不可见
- TextView 代码设置drawableLeft、drawableRight、drawableTop、drawableBottom
- Android学习笔记_31_通过后台代码生成View对象以及动态加载XML布局文件到LinearLayout
- Android学习笔记_31_通过后台代码生成View对象以及动态加载XML布局文件到LinearLayout
- android textview在code(代码)中设置图片 和XML设置图片
- 使用代码为textview设置drawableLeft
- 对android里布局文件当中的TextView对象设置事件监听,但是不响应问题解决
- 使用代码为textview设置drawableLeft
- Android 自定义view-如何设置TextView drawableLeft 图片大小?
- 在代码中更改Textviewdrawable中的图片
- 使用代码为textview设置drawableLeft
- 在java代码中设置TextView中DrawableLeft的方法
- 使用代码为TextView或者Button设置drawableLeft,top,ringht,buttom
- 代码中如何设置TextView为不可见
- TextView,Button的DrawableLeft,,Right 使用代码动态的设置
- Android中EditView TextView (padding失效)使用setBackgroundDrawable或setBackgroundResource则xml中设置的 Padding失效