Skip to content

Commit fee1bff

Browse files
committed
Add hideKeyboard
1 parent 885e7ee commit fee1bff

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

app/src/main/java/com/ahmadabuhasan/search/MainActivity.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.ahmadabuhasan.search;
22

3+
import android.content.Context;
34
import android.os.Bundle;
45
import android.text.Editable;
56
import android.text.TextWatcher;
67
import android.view.View;
8+
import android.view.inputmethod.InputMethodManager;
79
import android.widget.EditText;
810
import android.widget.Toast;
911

@@ -29,6 +31,7 @@ protected void onCreate(Bundle savedInstanceState) {
2931
super.onCreate(savedInstanceState);
3032
setContentView(R.layout.activity_main);
3133

34+
hideKeyboard();
3235
etSearch = findViewById(R.id.etSearch);
3336

3437
recyclerView = findViewById(R.id.data_recyclerView);
@@ -69,4 +72,12 @@ public void afterTextChanged(Editable s) {
6972
}
7073
});
7174
}
75+
76+
public void hideKeyboard() {
77+
View view = this.getCurrentFocus();
78+
if (view != null) {
79+
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
80+
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
81+
}
82+
}
7283
}

0 commit comments

Comments
 (0)