【问题标题】:android view url in xml layoutxml布局中的android查看url
【发布时间】:2010-01-27 05:34:38
【问题描述】:

我有一个使用 android xml 布局设置的布局。我想在文本视图中嵌入一个链接,这样如果您单击该链接,它就会在 android 浏览器中打开。那是怎么做的。似乎没有 url 视图或任何东西。

【问题讨论】:

    标签: android


    【解决方案1】:

    您应该能够只在 TextView 中包含 URL,然后在 Linkify 中包含它。还有一个Tutorial about Linkify 和自定义链接可能会有所帮助。

    【讨论】:

      【解决方案2】:

      以下是如何以不明显但通常需要的方式执行此操作。假设我们只想链接文本视图中的单词 blammo。当用户按下 blammo 时,浏览器会打开并将它们发送到 google.com

      试试这样的:

      class sampleTransformFilter implements TransformFilter {
          public String transformUrl(Matcher match, String url) {
              return "http://google.com";
          }
      }
      
      class sampleMatchFilter implements MatchFilter {
          public boolean acceptMatch(CharSequence s, int start, int end) {
              return true;
          }
      }       
      
      Pattern sampleMatcher = Pattern.compile("blammo");      
      String sampleURL =    "";
      Linkify.addLinks(textView, sampleMatcher, sampleURL, new sampleMatchFilter(), new sampleTransformFilter());
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-05
        • 2014-12-21
        • 2013-03-07
        • 2011-12-20
        • 1970-01-01
        • 2012-05-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多