1.EditText常用屬性
android:digits=”1234567890.+-*/%\n()”
限制輸入框中只能輸入自己定義的這些字符串 如果輸入其它將不予以顯示
android:phoneNumber=”true”
限制輸入框中只能輸入手機號碼
android:password=”true”
限制輸入框中輸入的任何內容將以”*”符號來顯示
android:hint=”默認文字”
輸入內容前默認顯示在輸入框中的文字
android:textColorHint=”#FF0000″
設置文字內容顏色
android:enabled=”false”
設置輸入框不能被編輯
android:inputType="textPassword"
設置輸入類型
2.EditText默認時不彈出軟鍵盤
方法一:
在 AndroidMainfest.xml中選擇哪個activity,設置windowSoftInputMode屬性爲 adjustUnspecified|stateHidden
< activity android:name=".Main"
android:label="@string/app_name"
android:windowSoftInputMode="adjustUnspecified|stateHidden"
android:configChanges="orientation|keyboardHidden">
方法二:
讓 EditText失去焦點,使用EditText的clearFocus方法
例如:
EditText edit=(EditText)findViewById(R.id.edit);
edit.clearFocus();
方法三:
強制隱藏Android輸入法窗口
例如:
EditText edit=(EditText)findViewById(R.id.edit);
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edit.getWindowToken(),0);
3.EditText 光標位置
EditText et = new EditText(getContext());
String text = "text";
et.setText(text);
et.setSelection(text.length());
4.多個EditText嵌套監聽問題
當多個EditText相互監聽的時候,記得edt_test.removeTextChangedListener(watcher);