I want to hide soft keyboard everywhere in my application permanently. So I can use my custom keyboard. I have checked many solutions but still soft keyboard is appearing. Here is my code to register searchview.
EditText mEditText;
SearchView mSearchView;
public void registerSearchView(final SearchView sview, final MenuItem searchItem ) {
mSearchView = sview;
SearchManager searchManager = (SearchManager) mHostActivity.getSystemService(Context.SEARCH_SERVICE);
mSearchView.setSearchableInfo(searchManager.getSearchableInfo(mHostActivity.getComponentName()));
mEditText = (EditText) mSearchView.findViewById(R.id.search_src_text);
ImageView closeButton = (ImageView) mSearchView.findViewById(R.id.search_close_btn);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mEditText.getText() == null || mEditText.getText().length() < 1) {
mSearchView.onActionViewCollapsed();
MenuItemCompat.collapseActionView(searchItem);
hideCustomKeyboard();
} else {
mEditText.setText("");
mSearchView.setQuery("", false);
}
//Collapse the search widget
}
});
mEditText.setOnTouchListener(onTouch);
mSearchView.setOnTouchListener(onTouch);
mEditText.setOnFocusChangeListener(oFocusChange);
mSearchView.setOnFocusChangeListener(oFocusChange);
mEditText.setOnClickListener(onClickListener);
mSearchView.setOnClickListener(onClickListener);
mSearchView.setOnSearchClickListener(onClickListener);
private View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
((InputMethodManager) mHostActivity.getSystemService(ActionBarActivity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(v.getWindowToken(), 0);
showCustomKeyboard(v);
v.clearFocus();
v.requestFocus();
}
};
private View.OnTouchListener onTouch = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent motionEvent) {
if (mEditText.getText()==null || mEditText.getText().length() < 1){
v.clearFocus();
v.requestFocus();
}
((InputMethodManager) mHostActivity.getSystemService(ActionBarActivity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(v.getWindowToken(), 0);
v.onTouchEvent(motionEvent);
return true;
}
};
private View.OnFocusChangeListener oFocusChange = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean b) {
if (b == false) {
hideCustomKeyboard();
} else {
((InputMethodManager) mHostActivity.getSystemService(ActionBarActivity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(v.getWindowToken(), 0);
showCustomKeyboard(v);
}
}
};
This will work as you can force android to hide the keyboard !!
public static void disableSoftInputFromAppearing(EditText editText) {
if (Build.VERSION.SDK_INT >= 11) {
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
editText.setTextIsSelectable(true);
} else {
editText.setRawInputType(InputType.TYPE_NULL);
editText.setFocusable(true);
}
}
above code will work foresure !!
as well for search view
mSearchView.clearFocus();
will solve the issue
Add this to you manifest :
<activity android:name="com.your.package.ActivityName"
android:windowSoftInputMode="stateHidden" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.