Skip to content

Commit dd2c5db

Browse files
committed
Hide Keypad on clicking outside the EditText
1 parent a6caa64 commit dd2c5db

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

app/src/main/java/fr/free/nrw/commons/upload/SingleUploadFragment.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fr.free.nrw.commons.upload;
22

3+
import android.app.Activity;
34
import android.content.Context;
45
import android.content.Intent;
56
import android.content.SharedPreferences;
@@ -11,6 +12,7 @@
1112
import android.support.v7.app.AlertDialog;
1213
import android.text.Editable;
1314
import android.text.TextWatcher;
15+
import android.util.Log;
1416
import android.view.LayoutInflater;
1517
import android.view.Menu;
1618
import android.view.MenuInflater;
@@ -136,11 +138,29 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
136138

137139
titleEdit.addTextChangedListener(textWatcher);
138140

141+
titleEdit.setOnFocusChangeListener((v, hasFocus) -> {
142+
if (!hasFocus) {
143+
hideKeyboard(v);
144+
}
145+
});
146+
147+
descEdit.setOnFocusChangeListener((v, hasFocus) -> {
148+
if(!hasFocus){
149+
hideKeyboard(v);
150+
}
151+
});
152+
139153
setLicenseSummary(license);
140154

141155
return rootView;
142156
}
143157

158+
public void hideKeyboard(View view) {
159+
Log.i("hide", "hideKeyboard: ");
160+
InputMethodManager inputMethodManager =(InputMethodManager)getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
161+
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
162+
}
163+
144164
@Override
145165
public void onDestroyView() {
146166
titleEdit.removeTextChangedListener(textWatcher);

app/src/main/res/layout/fragment_single_upload.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
android:paddingEnd="@dimen/standard_gap"
1313
android:paddingTop="@dimen/small_gap"
1414
android:theme="@style/DarkAppTheme"
15+
android:clickable="true"
16+
android:focusableInTouchMode="true"
1517
>
1618

1719
<EditText

0 commit comments

Comments
 (0)