3 回答

TA貢獻1155條經驗 獲得超0個贊
嘗試這個:
TextView t2 = (TextView) findViewById(R.id.text2);
t2.setMovementMethod(LinkMovementMethod.getInstance());
在 xml 中:
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/txtCredits"/>
如果您正在調用,請在 xml 中刪除自動鏈接setMovementMethod()。

TA貢獻1815條經驗 獲得超10個贊
您可以將網址保存在標簽中,如下所示:
social.setTag("https://google.com");
當你想獲取 url 時,請執行以下操作:
String url = (String) social.getTag();

TA貢獻1817條經驗 獲得超14個贊
Alhamdulillah 我的問題已經解決了
在你的XML中:
<TextView
android:id="@+id/social"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:layout_marginTop="350dp"
android:linksClickable="true"
android:text="@string/social"/>
在你的價值觀字符串中
<string name="social">in here social</string>
在你的java類中
TextView mSocial = (TextView) findViewById(R.id.social);
mSocial.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(https://google.com));
startActivity(intent);
}
});
將您的 TextView 設置為字符串“Social”,但如果單擊 TextView 可以轉到 google.com
添加回答
舉報