EditText繼承關係:View-->TextView-->EditText。
EditText的屬性很多,這裡介紹幾個:
android:layout_gravity="center_vertical"
設定控制項顯示的位置:預設 top,這裡置中顯示,還有bottom
android:hint="請輸入數字!"
設定顯示在空間上的提示資訊
android:numeric="integer"
設定只能輸入整數,如果是小數則是:decimal
android:singleLine="true"
設定單行輸入,一旦設定為true,則文字不會自動換行。
android:password="true"
設定只能輸入密碼
android:textColor = "#ff8c00"
字型顏色
android:textStyle="bold"
字型,bold, italic, bolditalic
android:textSize="20dip"
大小
android:capitalize = "characters"
以大寫字母寫
android:textAlign="center"
EditText沒有這個屬性,但TextView有,置中
android:textColorHighlight="#cccccc"
被選中文字的底色,預設為藍色
android:textColorHint="#ffff00"
設定提示資訊文字的顏色,預設為灰色
android:textScaleX="1.5"
控制字與字之間的間距
android:typeface="monospace"
字型,normal, sans, serif, monospace
android:background="@null"
空間背景,這裡沒有,指透明
android:layout_weight="1"
權重,控制控制項之間的地位,在控制控制項顯示的大小時蠻有用的。
android:textAppearance="?android:attr/textAppearanceLargeInverse"
EditText始終不彈出軟體機碼盤
1.EditText預設不彈出軟體機碼盤
方法一:
在 AndroidMainfest.xml中選擇哪個activity,設定windowSoftInputMode屬性為 adjustUnspecified|stateHidden
例如:<activity android:name=".Main"
android:label="@string/app_name"
android:windowSoftInputMode="adjustUnspecified|stateHidden"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
方法二:
讓 EditText失去焦點,使用EditText的clearFocus方法
例如:EditText edit=(EditText)findViewById(R.id.edit);
edit.clearFocus();
方法三:
強制隱藏AndroidIME視窗
例如:EditText edit=(EditText)findViewById(R.id.edit);
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edit.getWindowToken(),0);
2.EditText始終不彈出軟體機碼盤
例:EditText edit=(EditText)findViewById(R.id.edit);
edit.setInputType(InputType.TYPE_NULL);