如何禁用软键盘

问题描述 投票:0回答:1

我正在使用AutoCompleteTextView处理项目。我把一些按钮作为键盘工作问题是当我点击(焦点)在autocompletetextview上软键盘出现我不希望它出现在我尝试过使用这个。

View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    } 

但这似乎只有工作,如果我把它放在onclick(按钮),它用于隐藏键盘,而我需要完全禁用它...任何想法?

android android-softkeyboard autocompletetextview
1个回答
1
投票
public static void hideKeyboard(Activity activity) {
    View view = activity.findViewById(android.R.id.content);
    if (view != null) {
        InputMethodManager imm = 
            (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

你可以点击按钮调用此方法也许这可以帮助你。

© www.soinside.com 2019 - 2024. All rights reserved.