如题。求解。最好有一个小例子。
解决方案 »
- progressBar 子线程更新UI
- sqlite 命令失效
- 调用方法 急。。。
- android listview
- 在哪能新建WebProject ?eclipse有吗
- 【在线急等】关于Android OpenVPN的一个问题
- 各位大神求帮助!~我想实现点第一个spinner和第二个spinner时有不同的内容在view2出现,我现在还缺什么,实现不了,
- 请问建一个Android 进销存怎样实现与web端交互 怎样与sqlserver数据库连接
- Android版本更新修改版本号
- 请教一个简单安卓编程 谢谢
- LinearLayout中的edittext,当点击edittext的时候不能弹出软键盘
- 求助用过DroidBox或TaintDroid的大神
在有个HTML类有个静态方法把这String类型转成Html的就行了
android:autoLink="all"
TextView myTextView = (TextView) this.findViewById(R.id.textView1);
SpannableString sp = new SpannableString("这句话中有百度超链接,有高亮显示,这样,或者这样,还有斜体.");
sp.setSpan(new URLSpan("http://www.baidu.com"), 5, 7, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
sp.setSpan(new BackgroundColorSpan(Color.RED), 17 ,19,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
sp.setSpan(new ForegroundColorSpan(Color.YELLOW),20,24,Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), 27, 29, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
//SpannableString对象设置给TextView
myTextView.setText(sp);
//设置TextView可点击
myTextView.setMovementMethod(LinkMovementMethod.getInstance());
也可以直接用html
myTextView.setText(Html.fromHtml("<a href='http://www.google.cn'>google </a>"));
myTextView.setMovementMethod(LinkMovementMethod.getInstance());
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="aboutus"><center><b> <a href="http://www.google.com">google</a></b></center></string>
</resources>解析:
public static class AboutUsBuilder{
public static AlertDialog create(Context context) {
String aboutTitle = context.getString(R.string.about_us_title);
Spanned aboutText = Html.fromHtml(context.getString(
R.string.weather_aboutus, TextView.BufferType.SPANNABLE));
ScrollView mainView = new ScrollView(context);
TextView message = new TextView(context);
mainView.addView(message);
message.setPadding(5, 5, 5, 5);
message.setText(aboutText);
return new AlertDialog.Builder(context).setTitle(aboutTitle)
.setCancelable(true).setIcon(R.drawable.icon)
.setPositiveButton(android.R.string.ok, null).setView(
mainView).create();
}
}