textview富文本

lx912356858 2016-06-16 10:55:11
textview富文本如何实现
...全文
43 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
tudouzi007 2016-06-16
  • 打赏
  • 举报
回复
1、layout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="${relativePackage}.${activityClass}" > <TextView android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="20sp" /> <TextView android:id="@+id/textview2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:autoLink="all" android:padding="20sp" android:textSize="20sp" /> <TextView android:id="@+id/text2" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> 2、MainActivity package com.example.textviewfwb; import android.app.Activity; import android.os.Bundle; import android.text.Html; import android.text.method.LinkMovementMethod; import android.widget.TextView; public class MainActivity extends Activity { private TextView textView1, textView2, textView3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView1 = (TextView) this.findViewById(R.id.textview1); // 添加一段html的标志 String html = "<font color='red'>I love android</font><br><br><br>"; html += "<font color='#0000ff'><big><i>I love android</i></big></font><p>"; html += "<big><a href='http://www.baidu.com'>百度</a></big><br>"; CharSequence charSequence = Html.fromHtml(html); textView1.setText(charSequence); textView1.setMovementMethod(LinkMovementMethod.getInstance());// 点击的时候产生超链接 textView2 = (TextView) this.findViewById(R.id.textview2); String text = "我的URL:http://www.baidu.com\n"; text += "我的email:abcd@126.com\n"; text += "我的电话:+ 86 010-89487389"; textView2.setText(text); textView2.setMovementMethod(LinkMovementMethod.getInstance()); } // @Override // public boolean onCreateOptionsMenu(Menu menu) { // // Inflate the menu; this adds items to the action bar if it is present. // getMenuInflater().inflate(R.menu.main, menu); // return true; // } textView3 = (TextView) findViewById(R.id.text2); String text2 = "欢迎回来<font color='#0000ff'><a href='http://www.baidu.com'>百度</a></font>一下,马上知道"; CharSequence charSequence = Html.fromHtml(text2); textView3.setText(charSequence); textView3.setMovementMethod(LinkMovementMethod.getInstance()); }

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧