偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

在Android開發(fā)中如何移除EditText上的輸入焦點

移動開發(fā) Android
當我們創(chuàng)建一個帶EditText 或 AutoCompleteTextView的視圖時,在加載視圖時總是會把輸入的焦點自動移動到第一個輸入框。如何改成最終效果呢?且看本文詳解。

當我們創(chuàng)建一個帶EditText 或 AutoCompleteTextView的視圖時,在加載視圖時總是會把輸入的焦點自動移動到***個輸入框。如下圖所示:

帶EditText 或 AutoCompleteTextView的視圖

下面是mail.xml布局文件:

  1. <!--?xml version="1.0" encoding="utf-8"?--> 
  2. <linearlayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> 
  3.         <button android:id="@+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/button_text"> 
  4.         </button> 
  5.         <edittext android:hint="@string/hint" android:id="@+id/EditText01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text=""> 
  6.         </edittext> 
  7.         <button android:id="@+id/Button02" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/button_text"> 
  8.         </button> 
  9. </linearlayout> 
  10.  

我們如何才能把焦點從EditText上移除呢?最簡單的方法是創(chuàng)建一個不可見的(invisible)LinearLayout,LinearLayout將會把焦點從EditText上移走。

我們修改mail.xml布局文件,在EditText之前增加一個LinearLayout ,如下所示:

  1. <!--?xml version="1.0" encoding="utf-8"?--> 
  2. <linearlayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> 
  3.         <button android:id="@+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/button_text"> 
  4.         </button> 
  5. <linearlayout android:focusable="true" android:focusableintouchmode="true" android:layout_height="0px" android:layout_width="0px"> 
  6.         <edittext android:hint="@string/hint" android:id="@+id/EditText01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text=""> 
  7.         </edittext> 
  8.         <button android:id="@+id/Button02" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/button_text"> 
  9.         </button> 
  10. </linearlayout> 
  11. </linearlayout> 

最終效果如下所示:

最終效果

不需要任何代碼就把焦點移除了,是不是最簡單的解決方案?

希望本文對您有所幫助!

【編輯推薦】

  1. Windows Phone 7 免費線下培訓火熱報名中
  2. 在Android開發(fā)中調用Rest web服務
  3. 詳解谷歌官方教程 Android R5 NDK下載及安裝
  4. 詳解谷歌官方教程 Android插件ADT 9.0.0
  5. Android那些事兒 Android手機交互特性
責任編輯:佚名 來源: ideasandroid
相關推薦

2013-07-16 14:47:18

Android EdiEditText不彈出Android開發(fā)

2024-05-28 08:23:36

Android開發(fā)文本

2013-06-27 17:26:01

AndroidEditText

2021-11-29 14:26:53

FreeDOSLinux

2010-12-13 14:41:44

Android 2.3MyEclipse

2019-10-23 14:34:15

KotlinAndroid協(xié)程

2011-02-25 15:49:09

NecessitasQtAndroid

2011-06-15 18:38:17

Linux Qt Symbian

2019-09-24 19:00:41

Linuxrm命令unlink命令

2023-11-01 11:34:21

ContextAndroid

2024-01-30 08:56:55

性能監(jiān)控性能管理工具內存存儲

2015-10-14 10:02:33

ClojureScri Android

2017-08-15 19:20:51

AndroidHttpServer

2015-12-08 13:25:39

2012-02-28 10:33:27

Eclipse 3.7Android環(huán)境

2017-12-28 14:51:01

AndroidView焦點

2010-08-31 09:39:37

2011-08-29 14:40:04

UbuntuAndroid

2019-02-28 09:30:04

Ubuntusudo命令

2012-09-19 14:40:35

Worklight
點贊
收藏

51CTO技術棧公眾號