单击超链接时如何关闭 MaterialAlertDialog?

Posted

技术标签:

【中文标题】单击超链接时如何关闭 MaterialAlertDialog?【英文标题】:How to dismiss a MaterialAlertDialog when a hyperlink is clicked? 【发布时间】:2021-12-02 13:46:02 【问题描述】:

当点击消息中的超链接时,有没有办法关闭/取消 MaterialAlertDialog? 当前浏览器处于打开状态,当您返回应用程序时,对话框仍处于打开状态。 对于按钮,有一个侦听器,您可以在其中关闭/取消对话框。

我想要实现的是在点击链接时关闭对话框。

【问题讨论】:

【参考方案1】:
    将 onClickListener 添加到包含超链接的 TextView 中 返回后使用 onResume() 方法关闭对话框

【讨论】:

【参考方案2】:

在阅读了一些关于 setLinkMovementMethod 的内容后,我想到了一些类似的想法:

textView.setLinkMovementMethod(new TextViewLinkHandler() 
   // do my stuff ... 
   // if left blank, nothing will happen on click at the link, so leave it blank to do nothing
)

使用上面提到的 TextViewLinkHandler()

public abstract class TextViewLinkHandler extends LinkMovementMethod 
  // add a method to handle the click
  // extract the url and open it
  // then dismiss the dialog

但也许这不是正确的方法。 你怎么想的?

【讨论】:

以上是关于单击超链接时如何关闭 MaterialAlertDialog?的主要内容,如果未能解决你的问题,请参考以下文章