TextView的xml
  1. <TextView
  2. android:id="@+id/textciew1"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:background="#000"
  6. android:drawableRight="@drawable/button_nav_down"
  7. android:gravity="center_vertical"
  8. android:paddingLeft="16dp"
  9. android:paddingRight="16dp"
  10. android:text="展开"
  11. android:textColor="#fff"
  12. />

在代码中如果要修改drawableRight设置的图片可以使用

setCompoundDrawables(Drawable left,Drawable top,Drawable right,Drawable bottom)

Drawable可以通过 Drawable nav_up=getResources().getDrawable(R.drawable.button_nav_up);得到

但是API提示,setCompoundDrawables() 调用的时候,Drawable对象必须调用setBounds(int left, int top, int right, int bottom)方法,于是我们加一行代码就可以了

  1. nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());

代码合在一起是这样的:

  1. Drawable nav_up=getResources().getDrawable(R.drawable.button_nav_up);
  2. nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
  3. textview1.setCompoundDrawables(null, null, nav_up, null);

最新文章

  1. mysql 连接慢的问题(超过了1秒)
  2. tableView的高度问题
  3. Javascript事件冒泡机制
  4. DbInitializer.cs初始化过程中context.entityName.Add()遇到的类型不匹配错误
  5. 定义函数def
  6. div+css的前端工程师的价值体现在哪些方面?
  7. ecshop里Ajax.call()方法定义
  8. MVC视图与控制器分离简单描述
  9. MVC查询数据接收及校验
  10. 轻量级quill富文本编辑器
  11. Flex中的FusionCharts 2D折线图
  12. 图像旋转与图像缩放及Matlab代码实现
  13. &lt;iframe&gt; 标签 中 src 的三种形式. display , echart
  14. [Postman]代理(16)
  15. Redis在Windows上使用和集群配置
  16. Python 列表推导、迭代器与生成器
  17. 为C函数自动添加跟踪语句
  18. PHP接口开发加密技术实例原理与例子
  19. C# 图片和Base64之间的转换
  20. QT STUDY 模型-视图-控制器

热门文章

  1. 3G中的A-GPS移动定位技术
  2. c# 回调委托
  3. logo上线
  4. java中的动态代理机制
  5. Reading package lists... Error! 解决方案
  6. bzoj 2818: Gcd GCD(a,b) = 素数
  7. C#和SQl 注入字符串的攻击 和 防止注入字符转的攻击
  8. AfterEffects 关键帧辅助功能
  9. ubuntu中rar与unrar用法详解
  10. linux sudo apt-get用法详解