How to move to another view by click on text view with two different words. this is the string i am using.
By clicking Sign Up, you are indicating that you have read and agree to the
Term of Use and Privacy Policy.
i want to make these two words (Term of Use, Privacy Policy) in different color and clickable..
i know ho to make color for a particular word. i want to make it clickable .
It's much simpler to use HTML with links in TextView than creating multiple TextViews, taking care about layout, listeners etc.
In your activity or fragment:
In manifest
I recommend this library: https://github.com/klinker24/Android-TextView-LinkBuilder
it fits your requirement very well.
A quick overview:
copied form project's readme:
The main advantage to using this library over TextView's autolink functionality is that you can link anything, not just web address, emails, and phone numbers. It also provides color customization and touch feedback.
Based on Boy's response (and thank you for your response which helped me a lot), here is another way I implemented it without this '[' and ']' chars using an inner class to describe clickable words :
Hope this may help someone
EDIT : how to change link color and remove underline:
Create and use your own implementation of ClickableSpan like this :
In ClickableTextView implementation, what happens if string got a word with repeated ? suppose for example string is "I'm clickable and also this is clickable" then both the strings should be changed to Spannable string but it fails it that scenario, only one will be changed to spannable string.
I finally figured it out how to have multiple clickable parts in a TextView. It is important that they all have their own ClickableSpan! That is where I went wrong the first time testing it. If they have the same ClickableSpan instance, only the last set span is remembered.
I created a String with the required clickable area's surrounded by "[" and "]".
and here is the set TextView, the setMovementMehthod is also mandatory:
I have created this function, which will handle the creation of the clickable area's: