如圖所示:
一.如何設置軟鍵盤顯示搜索按鈕?
在XML在輸入框中加入android:imeOptions="actionSearch"
二.如何監聽搜索按鈕?
et_key.setOnEditorActionListener(newTextView.OnEditorActionListener() {
??????? @Override
???????? public booleanonEditorAction(TextView v, intactionId,KeyEvent event) {
?????????????? if(actionId == EditorInfo.IME_ACTION_SEARCH){
?????????????? // 先隱藏鍵盤
?????????????? ((InputMethodManager)et_key.getContext().getSystemService(Context.INPUT_METHOD_SERVICE))
?????????????????????? .hideSoftInputFromWindow(
?????????????????????????????? SearchActivity.this
?????????????????????????????????? .getCurrentFocus()
?????????????????????????????????? .getWindowToken(),
?????????????????????????????? InputMethodManager.HIDE_NOT_ALWAYS);
?????????????????? String keyWord =et_key.getText().toString().trim();
????????????????? searchByKeyWord(keyWord);
????????????????? return true;
??????????? }
???????????? return false;
?????? }
});
三.如何解決軟鍵盤會把原界面擠上去的問題?
在androidMainfest.xml文件中在此Activity中寫入 android:windowSoftInputMode="adjustPan"