TextView 部分字符高亮 android
来源:互联网 发布:淘宝飞利浦吹风机 编辑:程序博客网 时间:2024/05/20 10:13
[功能]
TextView是不支持部分字段高亮的 但是我们可以进行扩展
[思路]
1. 利用LinearLayout 作为 TextView 的 容器
2. 字符串中每个字都使用一个TextView显示之
3. 还可以使用*.9.png来作为所有TextView的背景 使之看上去成为整体
[思路 步骤]
TextHighlightHelper.java
TextHighlightUsage.java
public class TextHighlightUsage extends Activity{
TextHighlightHelper tHelper1;
TextHighlightHelper tHelper2;
LinearLayout ll;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.txt_high_light);
ll = (LinearLayout)findViewById(R.id.layout);
//Text:HelloText2
CharSequence c1 = "HelloText2";
tHelper1 = new TextHighlightHelper(this,LinearLayout.HORIZONTAL);
tHelper1.addText(c1);
tHelper1.addColor(0, 3, Color.RED);
tHelper1.addBackResource(R.drawable.icon);
ll.addView(tHelper1.loadView());
//Text:创新源于模仿!
CharSequence c2 = "创新源于模仿!";
tHelper2 = new TextHighlightHelper(this,LinearLayout.VERTICAL);
tHelper2.addText(c2);
tHelper2.addColor(1, 3, Color.RED);
ll.addView(tHelper2.loadView());
TextView tv = new TextView(this);
tv.setText(Html.fromHtml("<font color=/"#ff0000/">红色</font>其它颜色"));
ll.addView(tv);
}
}
txt_high_light.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:text="HelloText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
7. emulator 运行截图:
From:http://griffinshi.javaeye.com/blog/604444
- TextView 部分字符高亮 android
- Android TextView 部分字符高亮
- TextView 部分字符高亮
- Android 自定义textview 部分文字字体颜色高亮
- Android 文本阅读以及TextView指定字符高亮显示
- Android 高亮 TextView
- Android TextView 文字高亮
- android--设置TextView部分文字的颜色和背景(高亮显示)
- android--设置TextView部分文字的颜色和背景(高亮显示)
- android--设置TextView部分文字的颜色和背景(高亮显示)
- android--设置TextView部分文字的颜色和背景(高亮显示)
- 最新历史版本 :android--设置TextView部分文字的颜色和背景(高亮显示)
- android--设置TextView部分文字的颜色和背景(高亮显示)
- android--设置TextView部分文字的颜色和背景(高亮显示)
- android--设置TextView部分文字的颜色和背景(高亮显示)
- android--设置TextView部分文字的颜色和背景(高亮显示)
- android -- TextView 部分字符带颜色 与 popupwindow 的使用
- Android TextView设置显示指定字符,超过部分显示...(省略号)
- 解谷歌的一道题
- sql 小手册
- Asp.net的IsPostBack深入探讨
- socket 连接建立图
- 学JAVA,这些你都知道吗?(1)
- TextView 部分字符高亮 android
- 学JAVA,这些你都知道吗?(2)
- linq
- EIGRP RIPv2的路由协议
- ubuntu8.10 桌面版架设ecshop网
- Linux下Socket编程示范
- 听君一席话
- HashMap 的遍历
- ashx是有什么用?