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
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 .
Set android:autoLink="web"
on your TextView
in your layout XML, or you can use the solution here:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.