首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

text 文本式样粗斜体以及在listView中使用超链接

2012-09-13 
text 文本样式粗斜体以及在listView中使用超链接// Get our EditText object.EditText vw (EditText)fin

text 文本样式粗斜体以及在listView中使用超链接

// Get our EditText object.
EditText vw = (EditText)findViewById(R.id.text);

// Set the EditText's text.
vw.setText("Italic, highlighted, bold.");

// If this were just a TextView, we could do:
// vw.setText("Italic, highlighted, bold.", TextView.BufferType.SPANNABLE);
// to force it to use Spannable storage so styles can be attached.
// Or we could specify that in the XML.

// Get the EditText's internal text storage
Spannable str = vw.getText();

// Create our span sections, and assign a format to each.
str.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
str.setSpan(new BackgroundColorSpan(0xFFFFFF00), 8, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 21, str.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

http://developer.android.com/intl/zh-CN/guide/appendix/faq/commontasks.html

或者

mBox = new TextView(context); mBox.setText(Html.fromHtml("<b>" + title + "</b>" + ?"<br />" + ? ? ? ? ? ? ? ? ? ? ? ? "<small>" + description + "</small>" + "<br />" + ? ? ? ? ? ? ? ? ? ? ? ? "<small>" + DateAdded + "</small>");

想在listView中使用超链接 可以继承custom adapter并在getView

textcontent.setText(Html.fromHtml(item.get_text()));
textcontent.setAutoLinkMask(Linkify.WEB_URLS);
然后在

<TextView
? ? ? ? ? ? ? ? android:id="@+id/txtview"
? ? ? ? ? ? ? ? android:autoLink="web"
? ? ? ? ? ? ? ? android:layout_width="fill_parent"
? ? ? ? ? ? ? ? android:layout_height="fill_parent"
? ? ? ? ? ? ? ? android:text="put your link here"/>

?下标:

mtTextView.setText(Html.fromHtml("HC0<sub>3</sub>"));

热点排行