安卓增加超鏈接最簡便處理

在資源中配置

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="blog"><a href="http://www.szhuodong.com/html/2014/jjsz_0826/6510.html">9月6日 鹽田創意港飲食文化音樂節開幕</a></string>
    <string name="hello_world">活動列表</string>
    <string name="app_name">activity_shenzhen</string>
</resources>


然後在佈局頁面使用這些資源

<TextView
    android:id="@+id/mt_blog"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="40dp"
    android:text="@string/blog"
    android:textColor="#F5F5F5"
    android:textSize="18sp" />


代碼中通過id查找到超鏈接,進行跳轉

TextView t2 = (TextView) findViewById(R.id.mt_blog); 
t2.setMovementMethod(LinkMovementMethod.getInstance());


本文雖是原創,但參考了網上資料。如有雷同,請原諒。

發佈了22 篇原創文章 · 獲贊 6 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章