为什么链接不会在文本视图中工作? [英] Why link does not work in the text view?

查看:143
本文介绍了为什么链接不会在文本视图中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的链接在我的TextView:

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    ...    <的TextView
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:自动链接=所有
        机器人:linksClickable =真
        机器人:文字=@字符串/ app_description/>
< / RelativeLayout的>

链接是资源的一部分:

 <?XML版本=1.0编码=UTF-8&GT?;
<资源>
    ...
    <字符串名称=app_description>有的用文字的< A HREF =htt​​p://www.example.com>链接< / A>< /串>
< /资源>

不知何故,链接不起作用。可能是什么原因?
它显示像一个链接。但是,单击不打开浏览器。

类code:

  @覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);


解决方案

您可以使用HTTP链接是这样的:

  = MLINK(的TextView)findViewById(R.id.link);
      如果(MLINK!= NULL){
        mLink.setMovementMethod(LinkMovementMethod.getInstance());
     }

在XML:

 的android:自动链接=所有

I have the link in my TextView:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    ...

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:autoLink="all"
        android:linksClickable="true"
        android:text="@string/app_description" />
</RelativeLayout>

The link is a part of the resources:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    ...
    <string name="app_description">Some text with the <a href="http://www.example.com">link</a>.</string>
</resources>

Somehow the link doesn't work. What could be a reason? It is displayed like a link. But click doesn't open the browser.

Class code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

解决方案

you can use http link this way:

   mLink = (TextView) findViewById(R.id.link);
      if (mLink != null) {
        mLink.setMovementMethod(LinkMovementMethod.getInstance());
     }

In XML:

android:autoLink="all"

这篇关于为什么链接不会在文本视图中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆