Android Edittext獲取焦點後,彈出的軟鍵盤顯示搜索、發送、完成等功能
在EditText加一個屬性
android:imeOptions="actionSearch"(搜索)
android:imeOptions="actionSend"(發送)
android:imeOptions="actionNext"(下一項),
android:imeOptions="actionDone"(完成),
android:imeOptions="actionGo"(前往)等等;
有時候
android:imeOptions="actionSearch"(搜索)會不起作用,會顯示換行
這是因爲在2.3及以上版本不起作用,2.3以下就好使
這時加上android:singleLine="true"即可
如果設置了輸入類型
如:android:inputType="number"
android:imeOptions="actionSearch"(搜索)也會不起作用,會顯示換行
有時軟鍵盤會把原來的佈局擠上去
可以在androidMainfest.xml文件中在此Activity中寫入 android:windowSoftInputMode="adjustPan"
或者當返回時 先去隱藏軟鍵盤
InputMethodManager inputmanger = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputmanger.hideSoftInputFromWindow(arg0.getWindowToken(), 0);
有時候爲了佈局美觀,在搜索時沒有搜索按鈕,而是調用軟件盤上的按鈕。調用的實現只需要在XML在輸入框中加入Android:imeOptions="actionSearch",另外,還要設置android:singleLine="true",保證點擊不會換行,最後調用軟鍵盤時,回車鍵就會顯示搜索二字。
然後調用 OnEditorActionListener,不是OnKeyListener
|
|