I want to create a TextView with just a few words clickable. When user clicks on that link a Webview is created.
I also would like to change the color of the link as well.
In HTML I can do this:
<p>By checking this box, I acknowledge that I have reviewed the <a href="To the other page"> Online Payment Terms & Conditions</a> and agree.</p>
How do I create this in Android studio?
What I have so far:
- Layout XML:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/terms_condition_message"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
- Strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name"terms_condition_message"><![CDATA[By checking this box, I acknowledge that I have reviewed the %1$s<color="#fff3670b4">Online Payment Terms & Conditions</color>%2$s and agree.
2
Answers
Here is how I did it.
TextView:
Main Activity:
Blog that I used to help: https://medium.com/@sairamravuri/clickable-textview-in-kotlin-a242f7168b89
Add
android:linksClickable="true"
andandroid:textColorLink="@color/colorLink"
in your text view.Set
movementMethod
to TextView in Java or Kotlin class.In Kotlin:
In Java: