2

我正在尝试为 TextView 定义 autolink = "web"。令人惊讶的是,当我声明这一点时,TextView 中的文本被隐藏了,并且仅在第一次单击时才可见。这太令人惊讶了,我的应用程序的许多部分都具有相同的功能,并且可以正常工作。这是我唯一找不到问题所在的地方。

请帮我解决一下:

这是我的 TextView XML 代码:

<TextView
            android:id="@+id/details_webAddress_textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/details_location_textView"
            android:drawableLeft="@drawable/icon_website_earth"
            android:drawablePadding="5dp"
            android:gravity="center"
            android:padding="5dp"
            android:singleLine="true"
            android:autoLink="web"
            android:text="www.google.com"
            android:visibility="visible" />

以下是自动链接运行良好的 TextView:

<TextView
                android:id="@+id/websiteAddress_textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:autoLink="web"
                android:padding="5dp"
                android:singleLine="true"
                android:text="www.stackoverflow.com" />
4

2 回答 2

2

尝试使用:

TextView textLink = (TextView) findViewById(R.id.details_webAddress_textView);
textLink.setVisibility(View.INVISIBLE);
Button buttonDetails = (Button) findViewById(R.id.button);

buttonDetails.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                textLink.setVisibility(View.VISIBLE); // text visible on firt click
                String url = "http://www.example.com";
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url));
                startActivity(i); // open link with default browser
            }
        });
于 2016-01-25T14:31:20.493 回答
2

除了“android:autoLink”属性外,还需要在 xml 中设置“android:textColorLink”属性。

<TextView
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:autoLink="web"
     android:textColorLink="@color/yourDesiredLinkColor"/>
于 2016-11-16T15:08:02.717 回答