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);