2

I have a TextView in my app. It is a marquee text. I want to make this marquee text's links are clickable. How can i do this?

Thanks for help.

Edit: My codes:

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=" "

Java:

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

3 Answers3

1
  • Via XML:

    android:autoLink="web"
    
  • Via Code:

    txtView.setAutoLinkMask(Linkify.WEB_URLS)
    
iTurki
  • 16,292
  • 20
  • 87
  • 132
0

Try Linkify to add link to 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://");

For More Info Click Here.

Chirag
  • 56,621
  • 29
  • 151
  • 198
0

Set android:autoLink="web" on your TextView in your layout XML, or you can use the solution here:

How do I make links in a TextView clickable?

Community
  • 1
  • 1
Adam Monos
  • 4,287
  • 1
  • 23
  • 25