From c0effe7982d7be340059e68a35b8cb19d4995198 Mon Sep 17 00:00:00 2001 From: Long Date: Wed, 19 Sep 2018 17:46:58 -0700 Subject: [PATCH 1/2] Add "android:imeOptions="actionDone"" to EditText, so that we can easily hide the keyboard when we tap "Done" instead of having to click the device's back key. --- lazydatepicker/src/main/res/layout/layout_lazy_date_picker.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/lazydatepicker/src/main/res/layout/layout_lazy_date_picker.xml b/lazydatepicker/src/main/res/layout/layout_lazy_date_picker.xml index cc3ebb7..1438ea4 100755 --- a/lazydatepicker/src/main/res/layout/layout_lazy_date_picker.xml +++ b/lazydatepicker/src/main/res/layout/layout_lazy_date_picker.xml @@ -13,6 +13,7 @@ android:digits="0123456789" android:inputType="number|none" android:textSize="0sp" + android:imeOptions="actionDone" tools:ignore="LabelFor,TextFields" /> Date: Wed, 19 Sep 2018 18:06:19 -0700 Subject: [PATCH 2/2] Fix bugs where keyboard won't hide when application is paused, or when the EditText loses focus. --- .../lazydatepicker/LazyDatePicker.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lazydatepicker/src/main/java/com/mikhaellopez/lazydatepicker/LazyDatePicker.java b/lazydatepicker/src/main/java/com/mikhaellopez/lazydatepicker/LazyDatePicker.java index 4116f30..142300f 100755 --- a/lazydatepicker/src/main/java/com/mikhaellopez/lazydatepicker/LazyDatePicker.java +++ b/lazydatepicker/src/main/java/com/mikhaellopez/lazydatepicker/LazyDatePicker.java @@ -175,6 +175,15 @@ public void onClick(View v) { }); } + @Override + public void onWindowFocusChanged(boolean hasWindowFocus) { + super.onWindowFocusChanged(hasWindowFocus); + if (!hasWindowFocus) // onPause() called + { + hideKeyBoard(getContext()); + } + } + @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); @@ -197,6 +206,7 @@ public void onVisibilityChange(boolean isVisible) { public void onFocusChange(View v, boolean hasFocus) { showDate(date, hasFocus); showFullDateLayout(hasFocus); + if (!hasFocus) hideKeyBoard(getContext()); } }); @@ -551,6 +561,11 @@ private void showKeyboard(Context context) { InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); if (inputMethodManager != null) inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); } + + private void hideKeyBoard(Context context) { + InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); + if(imm != null) imm.hideSoftInputFromWindow(this.getWindowToken(), 0); + } //endregion //region UTILS