[英]Android hide soft keyboard from compound drawable
我有一個EditText,右邊有一個復合drawable。 當我按下drawable並清除文本時,我想要隱藏軟鍵盤。 為此,我有以下代碼:
filterText.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (filterText.getCompoundDrawables()[2] == null) {
// cross is not being shown so no need to handle
return false;
}
if (event.getAction() != MotionEvent.ACTION_DOWN) {
// only respond to the down type
return false;
}
if (event.getX() > filterText.getMeasuredWidth() -
filterText.getPaddingRight() - d.getIntrinsicWidth()) {
filterText.setText("");
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return false;
}
else {
return true;
}
}
});
但它不起作用,因為editText似乎保持焦點。 我試過過filterText.clearFocus,但沒辦法。
謝謝
只是一個建議:你不能在EditText
右側放置一個Button
嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.