如何在代码中更改textView在xml文件中设置好的drawable对象
来源:互联网 发布:算法导论 英文版 pdf 编辑:程序博客网 时间:2024/05/20 18:52
xml中的textView:
<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文件中设置好的drawable对象
- 如何在代码中设置textView跑马灯效果(不是在xml中)
- 在代码中修改TextView的Drawable图片
- 在代码中更改TextView中字体的颜色
- 在代码中设置Textview的drawableRight
- 在代码中设置textview的颜色
- 如何在代码中动态为TextView/Button设置drawableRight
- 在java代码中设置TextView中DrawableLeft的方法
- 在drawable文件中如何画圆
- TextView在代码中设置maxLength
- textview怎么在代码中设置图片
- 在带(继承)TextView的控件中,在代码中动态更改TextView的文字颜色
- xml只定义的textview如何在java中获得
- 关于在代码中设置TextView的颜色
- android在代码中设置TextView的颜色
- 关于在代码中设置TextView的textSize
- Android 在代码中为textview设置自定义的颜色
- 在代码中手动设置图片相对于TextView的位置
- 关于输入框的限制问题(百度百科转载)
- 一个简单的 弹性返回顶部JS代码
- Reactor与Proactor
- expect CU answer Forum
- PPT转EXE文件
- 如何在代码中更改textView在xml文件中设置好的drawable对象
- “Class Not Found Exception Spring"解决办法
- Android中Context详解 ---- 你所不知道的Context
- PHP模拟http请求
- Scrum Gathering开放分享:敏捷开发早期估算by火星人陈勇,北京,6.30!
- error LNK2001: unresolved external symbol "private: static int CAnimal::m_nType"
- 同步、异步、与阻塞、非阻塞的区别
- [问题解决方法汇总] ubuntu 12.04安装fbterm和yong输入法
- Java学习笔记之repaint,paint