简体   繁体   中英

Suppress Soft Input (hide keyboard) for Edittext view

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

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);
}

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);
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM