Creating An AutoLink Using TextView In Xamarin Android App


Xamarin is a platform to develop cross-platform and multi-platform apps (for example, Windows phone, Android, iOS). In Xamarin platform, the code sharing concept is used. The Xamarin Studio is available in Visual Studio too.


  • Visual Studio 2015 Update 3.

The steps, given below, are required to be followed in order to create an autoLink using TextView in a Xamarin Android app.

Step 1

Click File--> select New--> select Project. Or, click (Ctrl+Shift+N).


Step 2
After opening the New Project, go to Installed >> Templates >> Visual C# >> Android >> Blank App (Android).
Now, give your Android app a name (Ex:sample) and give the path of your project. Afterwards, click OK.


Step 3
Next, go to the Solution Explorer. Go to Resource --> Layout --> double click to open Main.axml page. 


Step 4

The Main.axml file will open the main page designer. In this page, you can select the mode (Designer or Source) as per your choice. 


Next, delete the default "Hello World" button. For this, go to the source panel and delete the button code from there. Similarly, delete the C# button code from the MainActivity.cs page.

Step 5

Now, go to the Toolbox window. Now, scroll down to all the tools and controls. Drag and drop the TextView.


Step 6

In this step, open the String.xml page. Go to the Solution Explorer --> Resource --> Values --> String.xml.


Step 7

After opening the String.xml file, write the following XML code.

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <string name="Hello">Hello World, Click Me!</string>  
  4.     <string name="ApplicationName">Auto_Link</string>  
  5.     <string name="website"></string>  
  6. </resources>  

Step 8

Now, go to the Properties window. You need to edit the TextView Id Value Text Value (EX  android:id="@+id/textView1" android:text="@string/website").


Step 9

Also, edit the autoLink value (Ex: android:autoLink="web" ).


Step 10

In this step, go to the Main.axml page Source Panel and note down the TextView id value.

  1. <LinearLayout xmlns:android="" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:minWidth="25px" android:minHeight="25px">  
  2.     <TextView android:text="@string/website" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/textView1" android:autoLink="web" /> </LinearLayout>  

Step 11

Go to the MainActivity.cs page in Solution Explorer. Write the following code in OnCreate() Method.

  1. protected override void OnCreate(Bundle bundle) {  
  2.     base.OnCreate(bundle);  
  3.     SetContentView(Resource.Layout.Main);  
  4. }  

Step 12

If you have Android Virtual device, run the app on it. Else, connect your Android phone and run the app in that. Simply, connect your phone and go to Visual Studio. The connected phone will show up in the Run menu (Ex LENOVO A6020a40(Android 5.1-API 22)).
Click the Run option.



After a few seconds, the app will start running on your phone. You will see that your app is running successfully.
Just click the Xamarin link.


Now, choose the browser.

The Xamarin website is working successfully.


So, this was the process of how to create an autoLink using TextView in Xamarin Android app, using Visual Studio 2015.

Up Next
    Ebook Download
    View all
    View all