Android练习之Linkify文字链接

code

 

View Code
 1 package com.example.flexe1;
 2 
 3 import android.os.Bundle;
 4 import android.app.Activity;
 5 import android.text.Editable;
 6 import android.text.method.KeyListener;
 7 import android.text.util.Linkify;
 8 import android.util.Log;
 9 import android.view.KeyEvent;
10 import android.view.Menu;
11 import android.view.View;
12 import android.view.View.OnKeyListener;
13 import android.widget.EditText;
14 import android.widget.TextView;
15 
16 /**
17  * Linkify.addLinks(textView, Linkify.All);
18  * 要用硬键盘输入
19  */
20 public class MainActivity extends Activity {
21     
22     private TextView tv1;
23     private EditText et1;
24 
25     @Override
26     protected void onCreate(Bundle savedInstanceState) {
27         super.onCreate(savedInstanceState);
28         setContentView(R.layout.activity_main);
29         
30         tv1 = (TextView)findViewById(R.id.tv1);
31         et1 = (EditText)findViewById(R.id.et1);
32         
33         et1.setOnKeyListener(new OnKeyListener() {
34             
35             @Override
36             public boolean onKey(View v, int keyCode, KeyEvent event) {
37                 tv1.setText(et1.getText());
38                 Log.i("keyCode:", String.valueOf(keyCode));
39                 Linkify.addLinks(tv1, Linkify.ALL);
40                 return false;
41             }
42         });
43         et1.setFocusable(true);
44     }
45 
46     @Override
47     public boolean onCreateOptionsMenu(Menu menu) {
48         // Inflate the menu; this adds items to the action bar if it is present.
49         getMenuInflater().inflate(R.menu.activity_main, menu);
50         return true;
51     }
52 
53 }

 

转载于:https://www.cnblogs.com/imzzh/archive/2013/02/17/2914162.html

你可能感兴趣的:(移动开发)