TextView如何显示丰富的文本

//布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.hzx.text_view1.MainActivity">

    <TextView
        android:id="@+id/textview1"
        android:padding="20sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
         />

    <TextView
        android:id="@+id/textview2"
        android:padding="20sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:autoLink="all"
        android:textSize="20sp"

        />
</LinearLayout>

//activity

public class MainActivity extends AppCompatActivity {

    private TextView textView1, textView2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        textView1 = (TextView)this.findViewById(R.id.textview1);
        textView2 = (TextView)this.findViewById(R.id.textview2);


        //添加一段html的标志
        String html = "<font color='red'>I love android</font><br>";
        html+="<font color='#0000ff'><big><i>I love android</i></big></font><p>";
        html+="<big><a href='http://www.baidu.com'>百度</a></big>";
        CharSequence charSequence = Html.fromHtml(html);
        textView1.setText(charSequence);
        textView1.setMovementMethod(LinkMovementMethod.getInstance());//点击时产生超链接

        String text = "我的URL: http:www.hao123.com\n";
        text+="我的email:abcd@126.com\n";
        text+="我的电话: + 86 010-89487389";
        textView2.setText(text);
        textView2.setMovementMethod(LinkMovementMethod.getInstance());
    }
}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,766评论 25 709
  • 用两张图告诉你,为什么你的 App 会卡顿? - Android - 掘金 Cover 有什么料? 从这篇文章中你...
    hw1212阅读 14,540评论 2 59
  • 1.什么是Activity?问的不太多,说点有深度的 四大组件之一,一般的,一个用户交互界面对应一个activit...
    JoonyLee阅读 11,046评论 2 51
  • 为了减少扬尘,柳州不少工地都设置有防尘降温的喷淋系统。然而,和平路上的喷淋系统,却让不少电动车一族十分厌恶...
    图羊阅读 1,346评论 0 1
  • 前几天别人传来一个消息,虽然是小道消息尚未经证实,仍然让我兴奋不已。有些人道别的时候想着此生不会再见了,完全不同的...
    pingangle阅读 1,571评论 0 0

友情链接更多精彩内容