Java 如何使链接在AlertDialog中可单击而不使用TextView?

Java 如何使链接在AlertDialog中可单击而不使用TextView?,java,android,Java,Android,我在strings.xml文件中有这一行: <string name="backup_help_body">Please watch this video if you did not understand the above steps: www.youtube.com</string> 如何在不使用文本视图的情况下,使链接在警报对话框中可单击 使用HTML格式: 例如: <string name="my_link"><a href="http://

我在strings.xml文件中有这一行:

<string name="backup_help_body">Please watch this video if you did not understand the above steps: www.youtube.com</string>
如何在不使用文本视图的情况下,使链接在警报对话框中可单击

使用HTML格式:

例如:

<string name="my_link"><a href="http://somesite.com/">Click me!</a></string>

供参考:

现在,为了使链接成为可点击的,您需要将LinkMovementMethod添加到相应的Textview

要获取相关的Textview,需要使用反射从AlertDialog获取mAlert字段,然后使用findviewbyId(android.R.id.alertTitle)

参考:


如果没有文本视图,我不确定您是否可以使用,我会使用自定义AlertDialog,但是您可以在代码中创建一个“临时”文本视图来执行您需要的操作,这里我将url保留在您有几个示例的地方


我认为最好、最快的方法(我所做的)是添加一个内置textview的自定义布局,然后在该textview上添加一个onClickListener


#超级容易做

同样的问题!我不能点击链接。我没有任何文本视图,你可以在我的代码中看到。我有一个ActionBar按钮,如果用户按下它,它将显示一个AlertDialog。AlertDialog包含使其可单击所需的链接。@MrGlitch在AlertDialog中,他们使用textview设置标题。你需要通过反射来获取它。目前,最简单的方法是使用自定义警报视图
<string name="my_link"><a href="http://somesite.com/">Click me!</a></string>