键盘未隐藏

时间:2018-10-20 10:53:54

标签: android keyboard

public static void hideKeyboard(Activity activity) {
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);

    View view = activity.getCurrentFocus();

    if (view == null) {
        view = new View(activity);
    }
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

它不起作用.... !!! 当我单击edittext时,此后将打开键盘,而当我单击另一个按钮时,键盘没有隐藏。

1 个答案:

答案 0 :(得分:0)

尝试在setShowSoftInputOnFocus(false)的实例上调用EditText

示例:

EditText editText = (EditText) findViewById(R.id.editText);
editText.setShowSoftInputOnFocus(false);

XML:

android:editable="false"
android:windowSoftInputMode="stateAlwaysHidden"
android:inputType="none"