如题。求解。最好有一个小例子。
解决方案 »
- A10开发板 热插拔切换hdmi和vga问题
- android 游戏中怎么根据图片的路径加载到程序中
- 如何让一个activity重新置顶?
- 存条短信出现莫名其妙的错误,请高手指点
- 初学android,创建工作报错
- android内存泄露机制,请高人指点
- osmdroid的显示不完整不清晰
- 关于”根据不同的平台版本选择不同主题"
- 一个activity 4个xml界面,其中3个是直屏,1个横屏,这个横屏的切换如何处理?
- 如何将两个Spinner的值和另一个EditText的值保存在一起???
- 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();
}
}