【问题标题】:Android SoftKeyboard on SurfaceViewSurfaceView 上的 Android 软键盘
【发布时间】:2012-06-09 14:13:37
【问题描述】:

我正在尝试在我的游戏中使用 SurfaceView 上的软键盘。问题是我无法处理 onKey 事件。

我已经尝试在我的视图上实现 OnKeyListener,并覆盖:

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    Log.w("Key", "Key Pressed");
    return true;
}

但我没有收到任何关键事件。

使用

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    Log.w("Key", "Key Pressed");
    return true;
}

也不行。

【问题讨论】:

    标签: android


    【解决方案1】:

    原来我必须在视图构造函数钩子上指定以下内容:

    setFocusable(true);
    setFocusableInTouchMode(true);
    

    因为输入事件只发送到焦点视图。

    【讨论】:

      猜你喜欢
      • 2011-03-14
      • 1970-01-01
      • 2019-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-30
      • 1970-01-01
      相关资源
      最近更新 更多