我有两个与ime_action_done有关的android活动。
活动A在EditText视图中有它。
那里 - 软键盘“完成”关闭了键盘。
private void initLayout(){
mInputText.setImeOptions(EditorInfo.IME_ACTION_DONE);
}
没有onEditorAction
重写
活动B在扩展TokenCompleteTextView
(com.tokenautocomplete.TokenCompleteTextView extends android.widget.MultiAutoCompleteTextView implements android.widget.TextView$OnEditorActionListener )
完成动作没有任何作用。
completionView.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (completionView.enoughToFilter() && (adapter != null)) {
//some logic. doesn't separate action_done from the other actions.
}
return true;
}
});
如何使第二个关闭软键盘?
答案 0 :(得分:1)
mInputText.setImeOptions(EditorInfo.IME_ACTION_DONE);
将操作设置为action_done(关闭键盘)
的默认操作在活动B中,我使用setOnEditorActionListener
来捕获ime_action并使用它。
所以我不得不在活动B中添加它:
completionView.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
InputMethodManager imm =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(completionView.getWindowToken(), 0);
}
或者像这样:
completionView.setImeOptions(EditorInfo.IME_ACTION_DONE);
completionView.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
//logic
}
return false;
}
});