最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 自動判斷是電話,網(wǎng)址,EMAIL方法之Linkify的使用

 更新時(shí)間:2013年04月21日 10:27:25   作者:  
本篇文章小編為大家介紹,在Android中 自動判斷是電話,網(wǎng)址,EMAIL方法之Linkify的使用。需要的朋友參考下

當(dāng)我們在一個(gè)EditText輸入電話或者網(wǎng)址還是Email的時(shí)候,讓Android自動判斷,當(dāng)我們輸入的是電話,我們點(diǎn)擊輸入內(nèi)容將調(diào)用打電話程序,當(dāng)我們輸入是網(wǎng)址點(diǎn)擊將打開瀏覽器程序.而Linkify很好的解決了這個(gè)問題

步驟:

1、布局UI

復(fù)制代碼 代碼如下:

<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中實(shí)現(xiàn)
復(fù)制代碼 代碼如下:

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,并自動與系統(tǒng)連接
    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"
/>

相關(guān)文章

最新評論

荣成市| 吕梁市| 彩票| 平乐县| 绵竹市| 历史| 尖扎县| 满洲里市| 剑河县| 庄浪县| 利津县| 西乌珠穆沁旗| 扬州市| 南川市| 石泉县| 虞城县| 扎囊县| 崇信县| 巨野县| 仪征市| 麻江县| 加查县| 乐陵市| 高淳县| 黔西| 蓬安县| 临安市| 陵川县| 潮安县| 桦甸市| 德安县| 泗阳县| 益阳市| 柏乡县| 梅州市| 德州市| 宜宾市| 马边| 怀宁县| 炉霍县| 罗甸县|