2 回答

TA貢獻1877條經(jīng)驗 獲得超1個贊
單擊完成按鈕時,調(diào)用hideSoftInputFromWindow
方法 -
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);

TA貢獻1807條經(jīng)驗 獲得超9個贊
public void hideSoftKeyboard(Context context, View view) {
try {
InputMethodManager inputMethodManager =
(InputMethodManager) context.getSystemService(
Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(
view.getWindowToken(), 0);
} catch (Exception e) {
e.printStackTrace();
}
}
用法
textinputEdit.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId==EditorInfo.IME_ACTION_DONE){
buttonConfirm.performClick();
hideSoftKeyboard(YourActivityName.this,textinputEdit);
}
return false;
}
});
添加回答
舉報