我如何prevent从弹出软键盘?弹出、键盘、prevent

2023-09-04 07:25:04 作者:一言不合拔刀就干

我有我自己的键盘在我的应用程序,所以我想隐藏软件键盘所有的时间(具体活动和放大器;对话框)。 我尝试了两种选择:

I have my own keypad in my application so I want to hide the software keyboard all the time(in specific activities & dialogs). I experimented with two options:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

这code prevent从弹出的开头,但是当我点击文本框的键盘仍然弹出键盘。

This code prevent the keyboard from popping up at the beginning, but when I click on the textbox the keyboard still pops.

InputMethodManager imm = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);

这code隐藏键盘,但它并没有prevent键盘的弹出。

This code hide the keyboard, but it doesn't prevent the keyboard from popping up.

请帮助!

推荐答案

终于想通了!

我用

public void supressKeyboard() {
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
}

有关,我想晚饭preSS键盘活动(你可以把它放在那里的所有其他活动,从继承一般的活动)

for the activities where I want to suppress the keyboard(you can put it in a general activity where all other activities inherit from)

但这并不prevent从弹出当你点击的EditText文本框的键盘。我所做的是我所消耗的onTouch事件的文本框中:

But this won't prevent the keyboard from popping up when you click on the EditText textbox. What I did is I consumed the onTouch event for the text box:

@Override
public boolean onTouchEvent(MotionEvent event) {
    return true;
}