Current days everybody using web for searching their needs so web-search engine is most popular.
This post is is clearly explainedhow do I make links in a TextView clickable in Android.
Following is my source code .
MainActivity.java
package com.example.hid;
import android.app.Activity;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:autoLink="web"
android:linksClickable="true"
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="20dp"
android:layout_centerVertical="true"
android:text="@string/web" />
</RelativeLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">hid</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="web">http://www.google.com</string>
</resources>
After wrote code I am running in my mobile phone using eclipse it giving following screen
After clicking user above on link it will trying to open google browser based on internet speed
Above screen is trying to open google page it opened some seconds difference
Finally i got google web page using my application it will useful when ever you need links in your application.
No comments:
Post a Comment