EditText去邊框,去下劃線 EditText的background屬性設置為@null就搞定了:android:background=”@null”
EditText不自動獲取焦點 在EditText的父Layout中,加入下面的兩個屬性即可: android:focusable=”true” android:focusableInTouchMode=”true”
設置光標位置 EditText的setSelection(int length)光標位置
光標顏色 EditText有一個屬性:android:textCursorDrawable,這個屬性是用來控制光標顏色的 android:textCursorDrawable=’@null’,’@null’作用是讓光標顏色和text color一樣
只能輸入數字或者某些特定字符 如何設置EditText,使得只能輸入數字或者某些字母呢?
一、設置EditText,只輸入數字:
方法1:直接生成DigitsKeyListener對象就可以了。
editText.setKeyListener(new DigisKeyListener(false,true));方法2:在EditText中設置屬性,android:numeric=”integer”即只能輸入整數,如下
<EditText android:singleLine="true" android:numeric="integer"/>方法3:新建一個char[],在里面添加允許輸入的字符。如下
editText.setKeyListener(new NumberKeyListener(){ PRotected char[] getAcceptedChars(){ return new char[]{'1','2','3','4','5','6','7','8','9','0'}; } public int getInputType() { //這個方法是控制輸入法鍵盤的,這樣輸入法就只會提供電話號碼的鍵盤 return android.text.InputType.TYPE_CLASS_PHONE; } });二、設置EditText只能輸入某些字母,如下面設置edtitext只能輸入A—D,a—f這些字母。方法如下:
editText.setKeyListener(new NumberKeyListener(){ protected char[] getAcceptedChars() //這個方法是返回自定義的字符的,這樣在手機輸入時,只有定義的字符才能寫到EditText中,其他的字符是寫不進去的 { char numberChars[]={'a','b','c','d','e','f','A','B','C','D'}; return numberChars; } public int getInputType() { //控制輸入法鍵盤的,不要控制的話就返回0就好了 return 0; }});EidtText屬性android:scrollbars=”vertical” 的神奇 下面兩張圖的別就是因為在內容的EditText中加了一個屬性:android:scrollbars=”vertical” 前: 內容的EditText中加了一個屬性:android:scrollbars=”vertical” 后:
新聞熱點
疑難解答