安卓:如何关闭IME的一个EditText?IME、EditText

2023-09-06 06:03:44 作者:谈情不如逗狗

我如何关闭的输入法的功能的EditText

How do I turn off the IME-functionality of an EditText?

?或:我如何避免输入法键盘的显示

Or: How do I avoid the display of the IME-keyboard?

我有一个布局在我的专用键盘位于下方的的EditText ,所以没有需要显示的IME。请理解,我无法实现我的键盘作为输入法,因为它是专用于这个非常的EditText ,并用它在任何其他情况下只会导致问题。

I have a layout where my special keyboard sits below the EditText so there's no need to show the IME. Please understand that I cannot implement my keyboard as IME as it is specific for this very EditText and using it in any other context would only cause problems.

我试图用

getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

的onCreate()活动的,但似乎并没有做在这种情况下任何东西。

in the onCreate() of the activity, but that doesn't seem to do anything in this situation.

推荐答案

想我找到了一种方法来做到这一点...子的EditText 并重写onCheckIsTextEditor()返回false:

Think I found a way to do it... subclass EditText and override onCheckIsTextEditor() to return false:

public class EditTextEx extends EditText {

    public EditTextEx(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override 
    public boolean onCheckIsTextEditor() {
        return false;
    }       
}

我测试过它,我不能让软键盘显示在所有。

I've tested it and I can't get the soft keyboard to show at all.