Reputation: 1337
I'm trying to make a simple calculator and to do so, I want to, and exit view that the user can move the courser within but can only input based off of the buttons I've included.
When I press on the Edittext view, however, the keyboard pops up and I can't figure out how to suppress it - I've tried both android:windowSoftInputMode="stateAlwaysHidden"
and android:configChanges="keyboardHidden"
in the manifest and also
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
//Hide keyboard
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
In Java but none of them work
Upvotes: 0
Views: 59
Reputation: 331
You can check that view is in focus and then hide the keyboard.
View view = this.getCurrentFocus(); if (view != null) { InputMethodManager manager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); manager.hideSoftInputFromWindow(view.getWindowToken(), 0); }
Upvotes: 0
Reputation: 1337
thanks for the help but I've just found a solution
XML:
<EditText
android:id="@+id/InputLine"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_above="@id/Sixth_Up"
android:onClick="hideKeyboard">
</EditText>
Java:
public void hideKeyboard(View v) {
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(editInput.getWindowToken(),0);
}
Upvotes: 1