更改与显示文字标签
2016-02-25 23:27
344 查看
更改与显示文字标签
在项目中新建一个TextViewActivity继承Activity的类并实现onCreate()方法。后创建一个textview.xml的布局文件。在布局文件中设置默认的根布局为LinearLayout,并添加一个TextView组件。<TextView android:id="@+id/TextView_tv01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:shadowColor="#FFFF00" android:shadowDx="1" android:shadowDy="1" android:shadowRadius="1" android:textColor="#888277" android:textSize="24sp"/> |
在TextViewActivity类中首先通过FindViewById()得到TextView的实例对象。
this.tv = (TextView)super.findViewById(R.id.TextView_tv01); |
this.tv.setText("Hello Android"); |
这里的setText()方法被重载了多次。
setText(CharSequence text)
setText(CharSequence text, BufferType type)
setText(char[] text,
int start, int len)
setText(int resid)
setText(int resid, BufferType type)
这里的BufferType是个enum的枚举类,里面保存了3个数值:NORMAL,SPANNABLE,
EDITABLE。
注意在Activity中,如果设置的Text设置的内容为HTML TAG。
如:
this.tv.setText("<a href = \"http://www.baidu.com\">百度</a>");
运行效果:
如果真的要在TextView中实现HTML的超链接,可以通过Html类的fromHtml()方法来实现。但是TextView中如果要实现可以点击的话,还需要先设置TextView的setMovementMethod()方法,里面传入LinkMovementMethod.getInstance()。如:
this.tv.setMovementMethod(LinkMovementMethod.getInstance());
this.tv.setText(Html.fromHtml("<a href = \"http://www.baidu.com\">百度</a>"));
相关文章推荐
- 项目检出JRE问题(Unbound classpath container: 'JRE System Library [JavaSE-1.7]' in project 'idweb')
- UVA 839(p157)----Not so Mobile
- Servlet_03_ServletConfig
- tornado的入门教程
- 安卓第三天笔记--通知-进度条-时期
- linux(ubuntu)设置以太网络
- html下拉框select及其选项option的初探
- UVA 821(p379)----Page Hopping
- React-JSX详解
- 设置窗体透明C#代码
- 二叉搜索树
- OC学习备忘
- 支付宝福卡破解——居中的ViewPager
- Android Studio——android坐标
- UVA 820(p380)----Internet Bandwidth
- bzoj 4373: 算术天才⑨与等差数列 hash
- 贪心算法知识点补充
- PHP程序的原子性和PHP的文件锁
- 2016年学习计划
- OS模块