Clickable Links and Emails
Android provides an autoLink attribute in text view. This is used to create links. This attributes provides links to web, email, phone, map and all. You don't need to provide any java code to make it functioning.
Sample Xml Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
android:gravity="center"
tools:context=".Main2Activity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Web Link"
android:textSize="30dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="https://firebase.google.com/"
android:autoLink="web"
android:textColorLink="@android:color/holo_green_light"
android:textSize="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:textSize="30dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="email"
android:textColorLink="@android:color/holo_red_light"
android:text="bhavinprajapat821@gmail.com"
android:textSize="20dp"/>
</LinearLayout>
Result:
Video Tutorial:
No comments:
Post a Comment