首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

彻底解决android surfaceview上触摸和键盘切换导致的键盘按键死锁现象

2012-08-30 
彻底解决android surfaceview下触摸和键盘切换导致的键盘按键死锁现象public GameEngine(Context context,

彻底解决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;

如果有触摸和键盘都需要的情况下 一定记得要加上这两行设置!

热点排行