在代码中修改TextView的DrawableRight图片
2024-10-15 12:52:16
TextView的xml
- <TextView
- android:id="@+id/textciew1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="#000"
- android:drawableRight="@drawable/button_nav_down"
- android:gravity="center_vertical"
- android:paddingLeft="16dp"
- android:paddingRight="16dp"
- android:text="展开"
- android:textColor="#fff"
- />
在代码中如果要修改drawableRight设置的图片可以使用
Drawable可以通过 Drawable nav_up=getResources().getDrawable(R.drawable.button_nav_up);得到
但是API提示,setCompoundDrawables() 调用的时候,Drawable对象必须调用setBounds(int left, int top, int right, int bottom)方法,于是我们加一行代码就可以了
- nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
代码合在一起是这样的:
- Drawable nav_up=getResources().getDrawable(R.drawable.button_nav_up);
- nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
- textview1.setCompoundDrawables(null, null, nav_up, null);
最新文章
- mysql 连接慢的问题(超过了1秒)
- tableView的高度问题
- Javascript事件冒泡机制
- DbInitializer.cs初始化过程中context.entityName.Add()遇到的类型不匹配错误
- 定义函数def
- div+css的前端工程师的价值体现在哪些方面?
- ecshop里Ajax.call()方法定义
- MVC视图与控制器分离简单描述
- MVC查询数据接收及校验
- 轻量级quill富文本编辑器
- Flex中的FusionCharts 2D折线图
- 图像旋转与图像缩放及Matlab代码实现
- <;iframe>; 标签 中 src 的三种形式. display , echart
- [Postman]代理(16)
- Redis在Windows上使用和集群配置
- Python 列表推导、迭代器与生成器
- 为C函数自动添加跟踪语句
- PHP接口开发加密技术实例原理与例子
- C# 图片和Base64之间的转换
- QT STUDY 模型-视图-控制器