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

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

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

【问题讨论】:

    标签: android hyperlink android-alertdialog dismiss


    【解决方案1】:
    1. 将 onClickListener 添加到包含超链接的 TextView 中
    2. 返回后使用 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
      }
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-08-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多