0

How do I make a link within string resource to be clickable and open a web page when the user clicks it?

<string name="about" translatable="false">
  Click <annotation font="lato_bold">. 
  <a href="https://google.com/">here</a></annotation> 
  for more information
</string>

I could do this with TextView but I don't know how to do it with string resources.

Thank You.

Mir Stephen
  • 1,758
  • 4
  • 23
  • 54

2 Answers2

1

You can do it from coding:

Kotlin:

var result:Textview = findViewById(R.id.myTextview)


result!!.movementMethod = LinkMovementMethod.getInstance()
            
            val text = "<a href='http://www.google.com'>Google.com</a>"
            result!!.text = Html.fromHtml(text)
Kamran Khan
  • 48
  • 1
  • 7
0

Change

<string name="about" translatable="false">
  Click <annotation font="lato_bold">. 
  <a href="https://google.com/">here</a></annotation> 
  for more information
</string>

to

<string name="about"> 
    <a href="https://google.com/">here</a>
</string>

You can directly use anchor tag inside string tag

Saurabh Dhage
  • 1,478
  • 5
  • 17
  • 31