Hide Keypad on clicking outside the EditText

This commit is contained in:
tanvidadu 2018-01-24 22:21:37 +05:30
parent a6caa64e17
commit dd2c5dbcb8
2 changed files with 22 additions and 0 deletions

View file

@ -1,5 +1,6 @@
package fr.free.nrw.commons.upload;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -11,6 +12,7 @@ import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -136,11 +138,29 @@ public class SingleUploadFragment extends CommonsDaggerSupportFragment {
titleEdit.addTextChangedListener(textWatcher);
titleEdit.setOnFocusChangeListener((v, hasFocus) -> {
if (!hasFocus) {
hideKeyboard(v);
}
});
descEdit.setOnFocusChangeListener((v, hasFocus) -> {
if(!hasFocus){
hideKeyboard(v);
}
});
setLicenseSummary(license);
return rootView;
}
public void hideKeyboard(View view) {
Log.i("hide", "hideKeyboard: ");
InputMethodManager inputMethodManager =(InputMethodManager)getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
@Override
public void onDestroyView() {
titleEdit.removeTextChangedListener(textWatcher);

View file

@ -12,6 +12,8 @@
android:paddingEnd="@dimen/standard_gap"
android:paddingTop="@dimen/small_gap"
android:theme="@style/DarkAppTheme"
android:clickable="true"
android:focusableInTouchMode="true"
>
<EditText