android 设置TextView的文本 上下左右 图标
来源:互联网 发布:苹果cms制作解析接口 编辑:程序博客网 时间:2024/05/22 03:39
android屌丝估计都知道,TextView是个文本控件,但是有的android新手可能还不知道TextVeiw还可以给文本的上下左右设置图标,下面我们就来说说怎么给TexteView设置图标
给TextView设置图标有两种方法:一种是在xml布局文件中设置,一种是通过java代码设置.方法如下:
1. xml布局文件中设置:
android:drawableLeft="@mipmap/ic_launcher"android:drawableTop="@mipmap/ic_launcher"android:drawableRight="@mipmap/ic_launcher"android:drawableBottom="@mipmap/ic_launcher"
2.java代码中设置:
TextView mTvMainTitleLeft = (TextView) findViewById(R.id.tv_title_left);// Drawable dwLeft = ContextCompat.getDrawable(getContext(), res); android studio中的获取方法 Drawable dwLeft = getResources().getDrawable(R.mipmap.ic_launcher); dwLeft.setBounds(0, 0, dwLeft.getMinimumWidth(), dwLeft.getMinimumHeight()); mTvMainTitleLeft.setCompoundDrawables(dwLeft, null, null, null);
以上就是给TextView设置图标的2中方式。
0 0
- android 设置TextView的文本 上下左右 图标
- Android动态设置TextView的文本格式
- Android TextView设置图标,调整图标大小
- Android TextView使用SpannableString设置复合文本的方法
- android:TextView设置文本样式和超链接
- Android TextView和EditText设置文本颜色
- Android之TextView设置String文本颜色
- Android之TextView设置String文本颜色
- 设置TextView 图标
- textView 设置右图标
- TextView中设置文本格式的方法
- TextView的文本设置(划线)
- TextView文本设置不同的样式
- textView 文本与边框的距离设置
- textview设置文本每行的行间距
- TextView文本省略号设置
- TextView设置文本颜色
- android文本组件textView属性autolink设置为web,显示网址的处理方法
- SPI、I2C、UART串行总线
- Tinker接入及源码分析(一)
- ValidatorException/SSLHandshakeException
- eclipse中的快捷键
- 统计降尺度与动力学降尺度
- android 设置TextView的文本 上下左右 图标
- 数据结构:散列1(分离链接法)
- OAuth2.0协议
- kafka(1)- kafka入门
- Android 系列 6.23让他们看打星标:使用RatingBar
- Linux for Matlab中文注释乱码(亲测有效)
- Center OS下的apache及openssl-cgi-bin访问。
- Android TabHost详解及事例(选项卡)
- android开发之this.finish()的使用