【问题标题】:Open URL in textView link在 textView 链接中打开 URL
【发布时间】:2019-09-03 18:52:11
【问题描述】:

我想在点击 textview 链接时打开 http://www.google.com。但它启动浏览器但在地址栏中显示 wwww.google.com%27 并产生错误。请提供解决方案。

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);    
  setContentView(R.layout.activity_main);
  TextView textView=(TextView)findViewById(R.id.textView1);
  textView.setClickable(true);
  textView.setMovementMethod(LinkMovementMethod.getInstance());
  String text="<a 'href=http://www.google.com'> Click to open Google!!! </a>";
  textView.setText(Html.fromHtml(text));

【问题讨论】:

    标签: java android textview


    【解决方案1】:

    尝试通过代码设置文本,使用Html对文本进行编码/解码

    Html.fromHtml(string)
    

    【讨论】:

    • 您好我是初学者,不知道如何编码/解码文本。你能解释一下吗
    • 试试这样的 'Html.fromHtml("google.com'> 点击打开谷歌!!!]]>"); '
    【解决方案2】:

    在 xml 中的 textview 元素中尝试 android:linkify="web"。这将打开浏览器。

    【讨论】:

      猜你喜欢
      • 2013-07-28
      • 2020-09-13
      • 1970-01-01
      • 2016-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-18
      • 2018-06-24
      相关资源
      最近更新 更多