public class AutoHideKeyboardEditText extends EditText {
protected boolean mHideKeyboardEnable = true;
public AutoHideKeyboardEditText(Context context) {
super(context);
}
public AutoHideKeyboardEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setHideKeyboardEnable(final boolean enabled) {
mHideKeyboardEnable = enabled;
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
if (mHideKeyboardEnable && !focused) {
// ソフトキーボードを非表示にする
final InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}
2015年10月17日土曜日
フォーカスが外れたとき、ソフトキーボードを非表示にするEditText
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿