【问题标题】:Put html link in edittext android将html链接放在edittext android中
【发布时间】:2013-09-26 06:33:34
【问题描述】:

我想把<a href="google.com" target="_blank">google</a> 放在edittext 中,当我点击这个文本时,我想打开webview。我该怎么做?

【问题讨论】:

  • 使用这个方法...setAutoLinkMask() 自动查找url和email id并使其可点击...

标签: android


【解决方案1】:

把你的html放在一个字符串中@

<string url="link">&lt;a href="http://www.google.com">Google&lt;/a></string>

设置String to editText@

youredittext.setText(Html.fromHtml(getResources().getString(R.string.url)));

对于点击,将LinkMovementMethod 设置为必要的操作@

youredittext.setMovementMethod(LinkMovementMethod.getInstance());

【讨论】:

    【解决方案2】:

    尝试添加以下代码:

    yourEditText.setMovementMethod(LinkMovementMethod.getInstance());
    

    【讨论】:

      【解决方案3】:

      试试这个

      EditText et = (TextView) findViewById(R.id.et);
      et.setText(Html.fromHtml("<a href=\"http://www.google.com/\">Google</a> "));
      et.setMovementMethod(LinkMovementMethod.getInstance());
      

      【讨论】:

        【解决方案4】:

        为什么要在 EditText 中使用它??

        如果您只使用带有文本“Google”的按钮,并使用它的 onclick 来调用 xml 中的方法,例如:

        android:onClick="openGoogleWebview"
        

        然后添加你的代码

        public void openGoogleWebview()
        {
             Intent intent = new Intent(this, GoogleWebviewActivity.class)
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-05-30
          • 1970-01-01
          • 2014-08-21
          • 2012-10-18
          • 2013-06-13
          • 2016-09-09
          相关资源
          最近更新 更多