我想在android AlertDialog中顯示一些文本和一些可點擊的單詞以打開網頁。我做的事情錯了,因爲它不會打開我告訴他和孔文本鏈接點擊,而我試圖避免.... 這是我的代碼:AlertDialog與網址和文字
final SpannableString s = new SpannableString(
Html.fromHtml("<br><a href=\"http://google.com\">a new link</a>")
);
final TextView tx1 = new TextView(this);
tx1.setText(getString(R.string.librarytextpart1)
+ s
+ getString(R.string.librarytextpart2));
tx1.setAutoLinkMask(RESULT_OK);
tx1.setMovementMethod(LinkMovementMethod.getInstance());
Linkify.addLinks(s, Linkify.ALL);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.library))
.setCancelable(false)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
}
})
.setView(tx1).show();
當點擊在對話框的SpannableString文本中,它顯示整個文本是可點擊的......並且仍然不打開網頁。當然,我不明白從文檔中的東西,但沒有看到什麼。你能幫忙嗎?