0

软键盘在我的活动中不起作用?但是在按下主页按钮或任何系统UI按钮后,除了返回按钮外,它的启动工作正常。

@Override
public boolean onKeyUp(int keyCode, final KeyEvent event) {
    final int finalKeyCode = keyCode;
    View lView = mParent.lET.findFocus();
    if(lView == mParent.lET)
    {
        if(keyCode == KeyEvent.KEYCODE_ENTER)
        {
            this.mGLThread.androidHideSoftKeyboard();
        }
        else
        {
            mParent.lET.bringToFront();
            mParent.lET.onKeyUp(finalKeyCode, event);
            mPlayerName = mParent.lET.getText().toString();
        }
    }

    return false;
}

硬件按钮触发此功能,但软键盘不起作用。谢谢。

4

3 回答 3

0

onKeyListener 通过软键盘在 Android 1.5 上完美运行

从 Android 1.6 开始,字符和数字键不再通过 onKey 事件,但 DEL 键可以

于 2013-03-15T05:57:07.420 回答
0

onKeyUp 应该处理硬件键而不是软键。所以你不能像这样处理软键盘的按键。为此,您可以做一件事。在 EditText 上设置 TextChangedListener。示例代码

edit.addTextChangedListener(new TextWatcher(){
            public void afterTextChanged(Editable s) {

            }
            public void beforeTextChanged(CharSequence s, int start, int count, int after){

            }
            public void onTextChanged(CharSequence s, int start, int before, int count){

            }

        });
于 2013-03-15T05:54:29.870 回答
0

试试这个

将您定义的侦听器设置为您的EditText

edittext.setOnEditorActionListener(new HideYourKeypad());

定义你的听众

    // Added try-catch just in case JellyBean has any other lurking errors
public class HideYourKeypad implements OnEditorActionListener {
    @Override
    public boolean onEditorAction(TextView view, int actionId,
            KeyEvent event) {
        try {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

            if (imm != null && view != null) {
                switch (actionId) {
                case EditorInfo.IME_NULL:
                    if ((event == null)
                            || (event.getAction() == KeyEvent.ACTION_DOWN))
                        imm.hideSoftInputFromWindow(view.getWindowToken(),
                                0);
                    return true;

                case EditorInfo.IME_ACTION_GO:
                    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                    return true;

                case EditorInfo.IME_ACTION_DONE:
                    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                    return true;
                }
            }
        } catch (Throwable x) {
            Logger.warning(TAG, "Error hiding keyboard", x);
        }

        return false;
    }
}
于 2013-03-15T06:00:26.123 回答