简体   繁体   English

如何在Android中使用超链接TextView创建AlertDialog

[英]How to create a alertdialog using hyperlinks textview in android

I have a Text view in hyperlink,when i click the link i want to open the alert dialog. 当我单击要打开警报对话框的链接时,我在超链接中有一个文本视图。 How to do this.i knew Separately to create the Alert dialog ,but using hyperlink am getting struggle. 如何做到这一点。我分别知道要创建“警报”对话框,但是使用超链接变得很困难。

My code 我的密码

policy.setText(Html.fromHtml("<a href>PasswordPolicy</a> "));

This involves a little trick, Use underline tag in strings.xml like below 这涉及一个小技巧,在strings.xml中使用下划线标记 ,如下所示

 <string name="tvideo"><u>Video</u></string>

Now set this in your TextView in the .xml 现在,在.xml中的T​​extView中进行设置

and setonclicklistener to that TextView and open your dialog. 并将setonclicklistener设置为该TextView并打开对话框。

Also note that output will be seen during run-time. 另请注意,将在运行时看到输出。 I'm afraid it will not be visible in Graphical Layout. 恐怕在“图形布局”中将不可见。

for that you need to create custom dialog and its text property as linkify. 为此,您需要创建自定义对话框,并将其文本属性设置为linkify。

TextView myWebSite = new TextView(this);
myWebSite .setText("http://http://www.google.com/");
Linkify.addLinks(myWebSite , Linkify.WEB_URLS);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM