软键盘在我的活动中不起作用?但是在按下主页按钮或任何系统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;
}
硬件按钮触发此功能,但软键盘不起作用。 感谢。
答案 0 :(得分: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){
}
});
答案 1 :(得分:0)
onKeyListener通过软键盘在Android 1.5上完美运行
从Android 1.6开始,字符和数字键不通过onKey事件,但DEL键确实
答案 2 :(得分: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;
}
}