效果:
[img]http://dl.iteye.com/upload/attachment/389845/9bc1d97b-b08c-375e-bcda-d504ed701371.jpg[/img]
点击下面的链接就进入了拨打电话的界面
[img]http://dl.iteye.com/upload/attachment/389849/7aa55f12-6f4d-3dea-b21e-f28939525f87.jpg[/img]
[img]http://dl.iteye.com/upload/attachment/389851/fdfa19a5-024f-33a1-b66e-e884f83b5d97.jpg[/img]
[img]http://dl.iteye.com/upload/attachment/389853/658d3f1f-8656-3531-9e8a-5c809e008c43.jpg[/img]
main.xml
[img]http://dl.iteye.com/upload/attachment/389845/9bc1d97b-b08c-375e-bcda-d504ed701371.jpg[/img]
点击下面的链接就进入了拨打电话的界面
[img]http://dl.iteye.com/upload/attachment/389849/7aa55f12-6f4d-3dea-b21e-f28939525f87.jpg[/img]
[img]http://dl.iteye.com/upload/attachment/389851/fdfa19a5-024f-33a1-b66e-e884f83b5d97.jpg[/img]
[img]http://dl.iteye.com/upload/attachment/389853/658d3f1f-8656-3531-9e8a-5c809e008c43.jpg[/img]
main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="22px"
android:layout_y="76px"
>
</TextView>
<EditText
android:id="@+id/edit"
android:layout_width="232px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_x="21px"
android:layout_y="25px"
>
</EditText>
</AbsoluteLayout>
package textView.linkify.test;
import android.app.Activity;
import android.os.Bundle;
import android.text.util.Linkify;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class TextViewLinkifyTest extends Activity {
private TextView text;
private EditText ed;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** 载入main.xm;*/
setContentView(R.layout.main);
/** 通过id找到TextView组件*/
text=(TextView)findViewById(R.id.text);
/** 通过id找到EditText组件*/
ed=(EditText)findViewById(R.id.edit);
/** 设置EditText键盘监听事件*/
ed.setOnKeyListener(new EditText.OnKeyListener(){
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
/** 设置TextView组件text内容*/
text.setText(ed.getText().toString());
/** 判断输入类型是哪些并与系统链接*/
Linkify.addLinks(text, Linkify.WEB_URLS|Linkify.EMAIL_ADDRESSES|Linkify.PHONE_NUMBERS);
return false;
}
});
}
}
本文展示了一个TextView组件链接化的示例应用,通过设置EditText监听事件并使用Linkify将文本中的网址、电子邮件地址及电话号码转换为可点击的链接。

被折叠的 条评论
为什么被折叠?



