【问题标题】:Linkify is adding %20 in my url and is not opening exact urlLinkify 在我的网址中添加 %20 并且没有打开确切的网址
【发布时间】:2014-04-29 05:24:39
【问题描述】:

我正在使用 android 的 linkify 功能打开一个网站,并在从我的设备打开时在我的 url 中获取 %20,我该怎么办?

这就是我正在做的事情

license=(TextView)findViewById(R.id.find_us_tv3);

    license.setTextSize(18);
    Pattern pattern=Pattern.compile("p"+"[page stackoverflow]+stackoverflow");

    license.setText(" Open the demo page stackoverflow.");
    license.setLinksClickable(true);
    Linkify.addLinks(license, pattern, "http://stackoverflow.com/questions/ask"); 

【问题讨论】:

    标签: android linkify


    【解决方案1】:

    您的代码中的“http://”
    "Linkify.addLinks(license, pattern, "http://https://stackoverflow.com/questions/ask")"
    两次没有帮助。

    只需使用:

    Pattern pattern = Pattern.compile("www.stackoverflow.com/questions/ask");
    Linkify.addLinks(license, pattern, "http://");  
    

    您在pattern 中提到的文字应该是您在TextView 中设置的文字的一部分

    参考:linkify blog link

    【讨论】:

    • 实际上我有大约 5 行的文本,我正在为给定的单词添加模式,比如许可证。并想在点击时打开特定网页。
    • 您可以只指定模式中的单词,这应该适用于您的文本视图
    • 是否打开了页面?
    • 不,我的链接与 Linkify.addLinks(license, pattern, "stackoverflow.com/questions/ask") 相同,并从设备添加 %20。(http 隐藏在评论中)
    • 请更改您的模式。编译并评估字符串值。也看看this,它在哪里添加 %20 ?
    【解决方案2】:

    试试这个:

    TextView tvWeblink = ((TextView) findViewById(R.id.textView));
            tvWeblink.setTypeface(LandingScreen.font);
    
            tvWeblink.setClickable(true);
            tvWeblink.setMovementMethod(LinkMovementMethod.getInstance());
            String text = "By pressing this It will open stack overflow page <a href=\"http://stackoverflow.com/questions/ask/\"> ask a question. </a>.";
            tvWeblink.setText(Html.fromHtml(text));
    

    【讨论】:

      猜你喜欢
      • 2011-09-17
      • 2018-09-27
      • 1970-01-01
      • 2019-05-17
      • 2012-04-12
      • 1970-01-01
      • 1970-01-01
      • 2017-04-25
      • 1970-01-01
      相关资源
      最近更新 更多