在做搜索框的時候,彈出的鍵盤當然也要對應,否則頗有點牛頭不對馬嘴的感覺。言歸正傳,其實要做的事情很簡單,有兩種方案
1. 在xml裏面對EditText進行屬性設置:
android:imeOptions="actionSearch"
android:inputType="text"
- java代碼中設置:
mEditText.setOnEditorActionListener(new OnEditorActionListener(TextView arg0,int arg1,KeyEvent arg2){
if(arg1 == EditorInfo.IME_ACTION_SEARCH | arg2 != null && arg2.getKeyCode() == keyEvent.KEYCODE_ENTER|){
// TODO 搜索按鍵的響應事件
}
)