When we are in a edittext input phone or URL or Email , let Android automatically judge, when we enter the phone, we click on the input will call the phone program, When we enter the URL click will open the browser program. and linkify solved the problem very well.
Steps:
1. Layout UI
Copy Code code as follows:
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical" >
<textview
Android:id= "@+id/tv"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"/>
<edittext
Android:id= "@+id/et"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"/>
<textview
Android:id= "@+id/tv1"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"/>
</LinearLayout>
2. Implement in Mainactivity
Copy Code code as follows:
public class Mainactivity extends activity {
Private TextView TV;
Private EditText et;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
TV = (TextView) Findviewbyid (R.ID.TV1);
ET = (edittext) Findviewbyid (r.id.et);
Et. Setonkeylistener (New Onkeylistener () {
@Override
public boolean OnKey (View v, int keycode, keyevent event) {
Tv.settext (Et.gettext ());
Decide whether to enter a URL or an email or a phonenumber, and connect to the system automatically
linkifyaddlinks (TV, Linkify.web_urls | linkify.email_addresses | Linkify.phone_numbers |);
return false;
}
});
}
}
ok! Easy way: In TextView, the following statement!
<textview
Android:id= "@+id/tv1"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:autolink= "Web|phone|email"
/>