彻底解决android surfaceview下触摸和键盘切换导致的键盘按键死锁现象
public GameEngine(Context context, AttributeSet attrs) { super(context, attrs); this.context = context; mSurfaceHolder = getHolder(); mSurfaceHolder.addCallback(this); thread = new Thread(this); setFocusable(true); setFocusableInTouchMode(true); BaseDebug.info(TAG, "GameEngine init over");}
?
分析上面的代码 重要的是2个关于焦点的设置
setFocusable(true);//设置键盘焦点
setFocusableInTouchMode(true)//设置触摸屏焦点
?
笔者开始没有设置触摸屏焦点 导致每次在触摸之后按键都会相应onFocusChanged并且gainFocus为false;
如果有触摸和键盘都需要的情况下 一定记得要加上这两行设置!