Reputation:
I have an input which is hidden from the view, Is there a way to stop an android device displaying the keyboard when focusing on the input?
Upvotes: 2
Views: 1279
Reputation: 36
If you want do disable focus only on androi device you have to detect user agent. You can use https://github.com/rafaelp/css_browser_selector. This plugin will add user agent to your html tag
$('.android input').on('focus', function (e) {
$(this).blur();
e.preventDefault();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text"/>
Upvotes: 2
Reputation: 125
public static void hideSoftKeyboard(Activity activity) {
if (activity.getCurrentFocus() != null) {
InputMethodManager inputMethodManager = (InputMethodManager) activity
.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
}
public static void hideSoftKeyboard(Fragment fragment) {
if (fragment.getActivity().getCurrentFocus() != null) {
InputMethodManager inputMethodManager = (InputMethodManager) fragment.getActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(fragment.getActivity().getCurrentFocus().getWindowToken(), 0);
}
}
Upvotes: 0
Reputation: 24211
Inside your onCreate
function.
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
You can also do it from your manifest file. Inside the <activity>
tag.
android:windowSoftInputMode="stateHidden"
Upvotes: 0