问题描述
三星Galaxy S4有的浮动触摸的功能,其中即使屏幕没有触摸手指可以被检测到。
Samsung Galaxy S4 have the "Floating Touch" functionality, in which the finger can be detected even if the screen is not touched.
我想触发一个事件上的一个按钮(BTN1)当手指通过悬停它。
I would like to fire an event on a button (btn1) when the finger is passing hover it.
我尝试使用OnHoverListener,但onHover从来没有被调用时,MotionEvent是MotionEvent.ACTION_HOVER_ENTER或MotionEvent.ACTION_HOVER_EXIT或MotionEvent.ACTION_HOVER_MOVE,这是我需要的事件。
I tried using the OnHoverListener, but "onHover" never get called when the MotionEvent is MotionEvent.ACTION_HOVER_ENTER or MotionEvent.ACTION_HOVER_EXIT or MotionEvent.ACTION_HOVER_MOVE, which are the event that I need.
这是我的code:
btn1.setOnHoverListener(new OnHoverListener() {
@Override
public boolean onHover(View v, MotionEvent event) {
Log.d("FloatingTouch", "onHover: "+event.getAction());
switch (event.getAction()) {
case MotionEvent.ACTION_HOVER_ENTER:
Log.d("FloatingTouch", "ACTION_HOVER_ENTER" );
return true;
case MotionEvent.ACTION_HOVER_MOVE:
Log.d("FloatingTouch", "ACTION_HOVER_MOVE" );
return true;
case MotionEvent.ACTION_HOVER_EXIT:
Log.d("FloatingTouch", "ACTION_HOVER_EXIT" );
break;
default:
break;
}
return false;
}
});
难道我错过了什么?也许一些权限?
Do I miss something? Maybe some permission?
推荐答案
好了,我终于得到它!
OK, I finally got it!
要使它工作,你必须:
To make it work you have to:
-
添加一个新的意图过滤器来com.sec.android.airview.HOVER您在清单活动:
Add a new intent filter to com.sec.android.airview.HOVER for your Activity in the manifest:
添加onHoverListener你查看
Add an onHoverListener to you View
convertView.setOnHoverListener(新OnHoverListener(){ @覆盖 公共布尔onHover(视图V,MotionEvent事件){ Log.d(ListAdapter,哈弗+项目); 返回false; }});
convertView.setOnHoverListener(new OnHoverListener() { @Override public boolean onHover(View v, MotionEvent event) { Log.d("ListAdapter", "Hover: " + item); return false; }});
它将作品。
这篇关于银河S4浮动触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!