Here I used clickable URL on Textview
and it works. But how can I set clickable and highlighted Text with Open URL with a browser. It's possible from Android XML OR kotlin without using java code like setText(Html.fromHtml(""))
.
String value = "<html>Visit Web <a href=\"http://www.domainname.com\">mysite</a> View</html>";
TextView text = (TextView) findViewById(R.id.text);
text.setText(Html.fromHtml(value));
text.setMovementMethod(LinkMovementMethod.getInstance());
<TextView
android:textSize="18sp"
android:autoLink="web"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="http://www.example.com"
tools:ignore="HardcodedText" />
It's No required declear layout id and no code from java side. it's works from xml
Use Autolink
android:autoLink="web"
android:autoLink="phone"
android:autoLink="email"
android:autoLink="web"
android:autoLink="all"
This property works for you TextView: android:autoLink="web"
here is an example Layout layout.xml
<TextView
android:id="@+id/txtLostpassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:autoLink="email"
android:gravity="center"
android:padding="20px"
android:text="@string/lostpassword"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/txtDefaultpassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:autoLink="web"
android:gravity="center"
android:padding="20px"
android:text="@string/defaultpassword"
android:textAppearance="?android:attr/textAppearanceSmall" />
string.xml
<string name="lostpassword">If you lost your password please contact <a href="mailto:[email protected]?Subject=Lost%20Password" target="_top">[email protected]</a></string>
<string name="defaultpassword">User Guide <a href="http://www.cleverfinger.com.au/user-guide/">http://www.cleverfinger.com.au/user-guide/</a></string>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With