我試着按照下面的例子來使我的警告對話框中點擊我的TextView的HTTP鏈接,但它不工作:HTTP鏈接對話框不工作
How do I make links in a TextView clickable?
我也只有這樣,得到它的工作是如果我把鏈接的文本直接放入我的字符串並將android:autoLink="web"
放入我的TextView中。但我不想看到整個鏈接,只是名稱。
這裏就是創建我的對話:
@Override
protected Dialog onCreateDialog(int id) {
LayoutInflater factory = LayoutInflater.from(this);
switch (id) {
case DISCLAIMER:
final View disclaimerView = factory.inflate(R.layout.disclaimer_dialog, null);
final TextView dtv = (TextView) disclaimerView.findViewById(R.id.disclaimer_body);
dtv.setText("v"+versionName+"\n\n\u00A9"+Calendar.getInstance().get(Calendar.YEAR)+" "+"Developer\n\n" +
getString(R.string.alert_dialog_disclaimer_body));
dtv.setMovementMethod(LinkMovementMethod.getInstance());
return new AlertDialog.Builder(MyActivity.this)
.setView(disclaimerView)
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.create();
}
return null;
}
,這裏是我的TextView位於R.layout.disclaimer_dialog
:
<TextView
android:id="@+id/disclaimer_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:gravity="center"
/>
這裏是我的字符串資源:
<string name="alert_dialog_disclaimer_body">This application was developed and written by me.\n\nGraphs use AChartEngine licensed under <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License 2.0</a>.\n\nThe rest goes here.</string>
嗯,我想你可能還需要'格式化= 「假」'字符串中的元素:'<字符串格式化= 「假」 名稱= 「alert_dialog_disclaimer_body」>'。 –
@ jsstp24n5我意識到真正的問題是什麼,並重寫了我的答案。 –
謝謝......在與html格式文檔爭鬥後,您對2個textviews的建議正是我在看到它之前所追求的。再次感謝。 – jsstp24n5