代码如下:
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、在MainActivity中实现
代码如下:
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());
// 判断输入的是URL还是EMAIL还是PHONENUMBER,并自动与系统连接
Linkify.addLinks(tv, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS |);
return false;
}
});
}
}
OK!简便方法:在TextView中如下申明!
TextView
android:id="@+id/tv1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="web|phone|email"
/