安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
来源:互联网 发布:淘宝网小衫 编辑:程序博客网 时间:2024/05/17 01:10
安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
TextView的xml文件
- <TextView android:id="@+id/tv_versionstatus"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:drawablePadding="5dp"
- android:drawableRight="@drawable/icon_new"
- android:text="版本"
- android:textColor="#363636"
- android:textSize="20sp" />
在代码中如果要修改drawableRight设置的图片可以使用API
void android.widget.TextView.setCompoundDrawables(Drawable left,Drawable top,Drawable right, Drawable bottom)
Drawable可以通过 Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_new); 得到。
但是API提示,setCompoundDrawables() 调用的时候,Drawable对象必须调用setBounds(int left, int top, int right, int bottom)方法,于是我们加一行代码就可以了。
- rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight());
整体代码如下:
- Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_new);
- rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight());
- tvVersionStatus.setCompoundDrawables(null, null, rightDrawable, null);
0 0
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- TextView 代码设置drawableLeft、drawableRight、drawableTop、drawableBottom
- Android在代码中设置控件的drawableLeft,drawableRight,drawableTop,drawableBottom。
- Android在代码中设置控件的drawableLeft,drawableRight,drawableTop,drawableBottom
- TextView设置drawableLeft,drawableRight,drawableTop和drawableBottom
- 绝对能用-动态设置textview的drawableleft、drawableright、drawabletop、drawablebottom
- View代码设置drawableLeft,drawableRight,drawableTop,drawableBottom
- 动态设置drawableTop,drawableLeft,drawableRight,drawableBottom
- 设置drawableTop、drawableLeft、drawableRight、drawableBottom图片大小
- android 动态设置drawableTop,drawableLeft,drawableRight,drawableBottom.
- Android控件设置——动态View的drawableLeft/ drawableRight/drawableTop/drawableBottom
- Java类与对象===Java访问修饰符(访问控制符)
- VS2010如何设置使得可以是程序利用argv参数来运行
- Lucene 实例教程(二)之IKAnalyzer中文分词器
- 从3张图了解Pinterest Feed算法与架构设计
- 记一次不愉快的bug修复
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 为什么 LR 模型要使用 sigmoid 函数,背后的数学原理是什么?
- 第1章 概述--主流PCB设计工具软件简介
- 页面间旋转跳转
- Cordova 环境搭建(Window)
- 【C语言】C语言字符串函数实现(二)
- Mysql常用的命令
- BlockingQueue
- 《你必须知道的.NET》读书笔记:内存分配等