Android Marquee TextView可点击链接

时间:2012-08-29 12:33:48

标签: android textview marquee

我的应用中有一个TextView。这是一个字幕文本。我想让这个字幕文本的链接可以点击。我怎么能这样做?

感谢您的帮助。

编辑:我的代码:

XML:

android:id="@+id/marquee_text"
android:autoLink="web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true" 
android:text=" "

爪哇:

marqueeText.setLinksClickable(true);
marqueeText.setText(marquee);//marquee is a string

3 个答案:

答案 0 :(得分:1)

  • 通过XML

    android:autoLink="web"
    
  • 通过Code

    txtView.setAutoLinkMask(Linkify.WEB_URLS)
    

答案 1 :(得分:0)

尝试使用Linkify添加指向textview的链接。

mTextSample = (TextView) findViewById(R.id.textSample);
String text = "Visit my blog jtomlinson.blogspot.com You can see Marquee also here";
mTextSample.setText(text);
//jmt: pattern we want to match and turn into a clickable link
Pattern pattern = Pattern.compile("jtomlinson.blogspot.com");
//jmt: prefix our pattern with http://
Linkify.addLinks(mTextSample, pattern, "http://");

了解详情Click Here

答案 2 :(得分:0)

在布局XML中的android:autoLink="web"上设置TextView,或者您可以在此处使用解决方案:

How do I make links in a TextView clickable?

相关问题