【发布时间】:2019-02-07 10:30:35
【问题描述】:
我有一个自定义对话框,里面有一个 Textview。我想在文本中添加一个超链接。我尝试使用setMovementMethod(LinkMovementMethod.getInstance()),但它仍然无法正常工作。但是,当我将它应用于不在我的自定义对话框中的文本视图时,它会起作用。
这是我的对话。
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(true);
dialog.setContentView(R.layout.license_dialog_layout);
TextView text = dialog.findViewById(R.id.text_dialog);
String str = "Link";
text.setText(context.getResources().getString(R.string.my_link, str));
dialog.show();
text.setMovementMethod(LinkMovementMethod.getInstance());
我的字符串资源:
<string name="my_link"><a href="https://www.google.com/">%1$s</a></string>
XML:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:id="@+id/text_dialog" />
【问题讨论】:
标签: android hyperlink dialog textview android-alertdialog