Looking at the android API, you have no intention of seeing linkify. According to API instructions, linkify can convert words that match the rules into clickable connections.
I think this is a little useful. Let's try it.
1. Create a project
2. Modify the Style File
Add an edittext and a textview to view the effect.
CodeAs follows:
<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Orientation = "vertical" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: weightsum = "1"> <edittext Android: layout_height = "wrap_content" Android: layout_width = "fill_parent" Android: id = "@ + ID/inputtext"> <requestfocus> </edittext> <textview Android: layout_height = "wrap_content" Droid: textappearance = "? Android: ATTR/textappearancelarge "Android: layout_width =" fill_parent "Android: layout_weight =" 0.08 "Android: Id =" @ + ID/viewtext "Android: TEXT = "Enter the content"> </textview> </linearlayout>
3. Modify androidlearnactivity. Java
Let's take a look at the key parts.
In this example, we use the first one. Let's take a look at what linkify supports by default.
Map_addresses I do not understand...
The complete code is as follows:
Package CN. ghy. sdx;
Import Android. App. activity;
Import Android. OS. Bundle;
Import Android. Text. util. linkify;
Import Android. View. keyevent;
Import Android. View. view;
Import Android. View. View. onkeylistener;
Import Android. widget. edittext;
Import Android. widget. textview;
Public Class Androidlearnactivity Extends Activity {
Edittext;
Textview;
@ Override
Public Void Oncreate (bundle savedinstancestate ){
Super . Oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Edittext = (edittext)This . Findviewbyid (R. Id. inputtext );
Textview = (textview) This . Findviewbyid (R. Id. viewtext );
Edittext. setonkeylistener ( New Onkeylistener (){
@ Override
Public Boolean Onkey (view V, Int Keycode, keyevent event ){
Textview. settext (edittext. gettext ());
Linkify. addlinks (textview, linkify. email_addresses | linkify. phone_numbers | linkify. web_urls );
Return False ;
}
});
}
}
Effect:
URL:
Tel:
Email:
Advanced learning:
The Several built-in functions of linkify can meet the needs, but sometimes they have more flexible needs. For example, you need to enter an ID card number.
I am not very clear about regular expressions. It is easy to use.
Textview. settext (edittext. gettext ());
Pattern pattern = pattern. Compile ("\ D {15} | \ D {18 }");
String scheme = "http: // chaxun? Sfz = ";//This is free to write.
Linkify. addlinks (textview, pattern, scheme );
Effect: