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 ;
        CharSequence charSequence = Html.fromHtml(html);
        textView1.setText(charSequence);
        textView1.setMovementMethod(LinkMovementMethod.getInstance());//點擊時產(chǎn)生超鏈接

        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());
    }
}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,932評論 25 709
  • 用兩張圖告訴你,為什么你的 App 會卡頓? - Android - 掘金 Cover 有什么料? 從這篇文章中你...
    hw1212閱讀 13,950評論 2 59
  • 1.什么是Activity?問的不太多,說點有深度的 四大組件之一,一般的,一個用戶交互界面對應一個activit...
    JoonyLee閱讀 5,856評論 2 51
  • 為了減少揚塵,柳州不少工地都設置有防塵降溫的噴淋系統(tǒng)。然而,和平路上的噴淋系統(tǒng),卻讓不少電動車一族十分厭惡...
    圖羊閱讀 181評論 0 1
  • 前幾天別人傳來一個消息,雖然是小道消息尚未經(jīng)證實,仍然讓我興奮不已。有些人道別的時候想著此生不會再見了,完全不同的...
    pingangle閱讀 232評論 0 0

友情鏈接更多精彩內(nèi)容