Blogger Text

My Aim to Provide you quality contents, Tips & Tricks, Software, Microsoft Office, Graphic Editing (Adobe PhotoShop, After Affects, Illustrator, inDesign) Corel Draw, Corel Video Studio, Cyberlink PowerDirector, Power ActionCinema, Tutorials about Blogging and VU Assignments, Quizes & GDB Solutions and Much More... at regular Basis
                                     ***    Kindly Subscribe our Official YouTube Channel "INFOPALACESS OFFICIAL-Tuts: in this channel we upload Programming (C,C++,C# JAVA, PHP), Web Development, Graphics Editing and Microsoft Office Step by Step Tutorials from bigginer to Advance Level. We also provide free online courses at our YouTube Channel. ***   Graded Assignments/Quizes and GDB will start in Next Week. Solution ideas of All assignments, Quizes and GDB will be available here. If you have any problem regarding this then you can contact us.

How to Add and Open Links from TextView in Android Studio

Here I am going to explain a very simple method to implementing hyperlinks to any TextView in android studio.
For better understanding watch the video below (In HD+ Quality) for step by step guidance.
 Steps involved in video also described below:
There are following 3 steps involved to Create a Static Clickable Link Inside the TextView.  
1-  Adding TextView in Activity
2-  Adding String in string.xml
3-  Implementing code in MainActivity.java

1-  Adding Some TextView

First of all we need to add TextView into Main-activity.xml

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/text1"
    android:id="@+id/weblink"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
/>

  
2-  Adding A New String into String.xml


Now Go to res à values à string on left side menu and create a new string as like this string in strings.xml:


<string name="infopalacesslink"><a href="http://www.infopalacess.com">Go To My Website</a></string>

3-  Implementing code in MainActivity.java

Now Go to “MainActivity.java” and write this code:
TextView text = (TextView) findViewById(R.id.textview);
text.setMovementMethod(LinkMovementMethod.getInstance());

For more detail please refer to Picture below: 
 

You are done! You should get a TextView like the one in the following screenshot and when you tap on the hyperlink the browser should open! Cool!
 

  Note!   you want to open a static link without doing other operations? So just follow the first part of this tutorial! Otherwise, if you want to have more control on the link customization and operations after the user taps on it, follow the second part of the tutorial which will come later.

Post a Comment

0 Comments