Maybe you need to add links to a TextView on Android but you don’t want to use Linkify for some reasons and you also want that link to be opened when the user taps it.
Here is a simple solution:
yourTextView.setText(Html.fromHtml( "Text with a " + "<a href=\"http://www.myandroidsolutions.com/\">link to My Android Solutions</a> ")); // this is important as well !! yourTextView.setMovementMethod(LinkMovementMethod.getInstance());
Note that I used the fromHtml() method from the Html class to generate a Spanned object that maps the given Html string into something that the TextView will know how to display.
You can use that to add other Html styles to your text when you display it in a TextView but you need to make sure you know the supported tags.
I extracted the supported tags from the source code ad you can find those below.
Supported HTML tags by the Html Android class:
– h (1 to 6)
Search In Blog
Want to donate?
Recent Posts: My Android Solutions
If you ever wondered how to read and parse a simple JSON file stored in the assets directory of your Android project, here is a way to do it.
In this tutorial I will create a simple Sectioned RecyclerView that will show 2 sections and a few items in each section and how to move an item from one section to another. Note: For RecyclerView I used AndroidX imports and not android.support.v7.widget.RecyclerView! Setup We need to import the recycler view from AndroidX. The build.gradle…
Recently, I had to add a perfect square CardView and I wanted to achieve this without hardcoding its width and height. I happily discovered the power of ConstraintLayout and this is how I managed to create a perfect square which should work on every dimension. In my project I created a RecyclerView with 2 columns,…