TextView的一些使用
2015-08-09 16:23
489 查看
TextView可以添加一些html字段
String html = "<fontcolor='red'>android</font><br>";
// color值可以用文本表示,也可以用十六进制值的文本颜色也可以用RGB表示(比如 "rgb(255,0,0)"。
// 属性值用单引号
html += "<fontcolor='#0000ff'><big><i>I love android</i></big></font><p>";
// <big>表示粗体 <i>
表示斜体
html += "<big><ahref='http://www.baidu.com'>百度</a></big>";
CharSequence charSequence = Html.fromHtml(html);
tv1.setText(charSequence);
// 点击的时候产生超链接。
tv1.setMovementMethod(LinkMovementMethod.getInstance());
此方法一定要在layout中为Textveiw设置android:autoLink=all;
String text = "URLhttp://www.sina.com\n";
text += "email:sanlan@163.com\n";
text += "电话 :159 0064 0525";
tv2.setText(text);
tv2.setMovementMethod(LinkMovementMethod.getInstance());
2 。利用反射得到工程中的资源
public
intgetResourceId(String name) {
try {
// 根据资源的ID变量名来获得filed对像,使用反射机制(Field是反射reflect中的)
Field field = R.drawable.class.getField(name);
// 取得并返回资源ID字段(静态变量)的值,使用反射机制
return Integer.parseInt(field.get(null).toString());
} catch(Exception e) {
}
return 0;
}
让图片产生超连接
String html = "图片1<img src='ic_launcher'/>图片2<img src='label_6'/>图片3<img
src='label_7'/><p>";
html += "图片4<a href='http://www.baidu.com'><imgsrc='ic_launcher'></a>";
CharSequence charSequence = Html.fromHtml(html,new ImageGetter() {
public DrawablegetDrawable(String source) {
Drawable drawable =getResources().getDrawable(getResourceId(source));
drawable.setBounds(0,0, drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
return drawable;
}
}, null);//这里一定要设置边框(setBound),否则图片无法显示。
tv.setText(charSequence);
tv.setMovementMethod(LinkMovementMethod.getInstance());
3.给TextView设置跑马灯效果。TextView中几个关键属性
android:singleLine="true"
android:ellipsize="marquee"
跑马灯效果
android:marqueeRepeatLimit="marquee_forever"重复
android:focusable="true"
android:focusableInTouchMode="true"
4,getField获得类中指定的public属性(也叫字段);getDeclaredField返回指定类中指定的属性(任何可见性)
String html = "<fontcolor='red'>android</font><br>";
// color值可以用文本表示,也可以用十六进制值的文本颜色也可以用RGB表示(比如 "rgb(255,0,0)"。
// 属性值用单引号
html += "<fontcolor='#0000ff'><big><i>I love android</i></big></font><p>";
// <big>表示粗体 <i>
表示斜体
html += "<big><ahref='http://www.baidu.com'>百度</a></big>";
CharSequence charSequence = Html.fromHtml(html);
tv1.setText(charSequence);
// 点击的时候产生超链接。
tv1.setMovementMethod(LinkMovementMethod.getInstance());
此方法一定要在layout中为Textveiw设置android:autoLink=all;
String text = "URLhttp://www.sina.com\n";
text += "email:sanlan@163.com\n";
text += "电话 :159 0064 0525";
tv2.setText(text);
tv2.setMovementMethod(LinkMovementMethod.getInstance());
2 。利用反射得到工程中的资源
public
intgetResourceId(String name) {
try {
// 根据资源的ID变量名来获得filed对像,使用反射机制(Field是反射reflect中的)
Field field = R.drawable.class.getField(name);
// 取得并返回资源ID字段(静态变量)的值,使用反射机制
return Integer.parseInt(field.get(null).toString());
} catch(Exception e) {
}
return 0;
}
让图片产生超连接
String html = "图片1<img src='ic_launcher'/>图片2<img src='label_6'/>图片3<img
src='label_7'/><p>";
html += "图片4<a href='http://www.baidu.com'><imgsrc='ic_launcher'></a>";
CharSequence charSequence = Html.fromHtml(html,new ImageGetter() {
public DrawablegetDrawable(String source) {
Drawable drawable =getResources().getDrawable(getResourceId(source));
drawable.setBounds(0,0, drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
return drawable;
}
}, null);//这里一定要设置边框(setBound),否则图片无法显示。
tv.setText(charSequence);
tv.setMovementMethod(LinkMovementMethod.getInstance());
3.给TextView设置跑马灯效果。TextView中几个关键属性
android:singleLine="true"
android:ellipsize="marquee"
跑马灯效果
android:marqueeRepeatLimit="marquee_forever"重复
android:focusable="true"
android:focusableInTouchMode="true"
4,getField获得类中指定的public属性(也叫字段);getDeclaredField返回指定类中指定的属性(任何可见性)
相关文章推荐
- GUI - Web前端开发框架
- 评价ui设计作品好坏的八个标准(界面/交互设计研究)
- 为Yahoo! UI Extensions Grid增加内置的可编辑器
- Cocos2d-x UI开发之文本类使用实例
- 在IE 浏览器中使用 jquery的fadeIn() 效果 英文字符字体加粗
- UI Events 用户界面事件
- 基于jQuery UI CSS Framework开发Widget的经验
- jquery ui 1.7 ui.tabs 动态添加与关闭(按钮关闭+双击关闭)
- jQuery UI的Dialog无法提交问题的解决方法
- 关于jQuery UI 使用心得及技巧
- jQuery ui 1.7更新小结
- 从零开始学习jQuery (十) jQueryUI常用功能实战
- jquery ui对话框实例代码
- jQuery UI AutoComplete 自动完成使用小记
- jQuery UI Autocomplete 体验分享
- Android UI使用HTML布局方法实例
- 浅谈AnDroidDraw+DroidDraw实现Android程序UI设计的分析说明
- aspx实现的 jquery ui 的 flexgrid demo
- Expandable "Detail" Table Rows
- Android 使用XML做动画UI的深入解析