Floating Touch on Galaxy S4(Galaxy S4 上的浮动触控)
问题描述
Samsung Galaxy S4 具有Floating Touch"功能,即使不触摸屏幕也可以检测到手指.
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
,但是当 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.
这是我的代码:
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?
推荐答案
好的,我终于明白了!
要让它发挥作用,你必须:
To make it work you have to:
- 为清单中的 Activity 添加一个新的 Intent 过滤器到
com.sec.android.airview.HOVER
:
<intent-filter>
<action android:name="com.sec.android.airview.HOVER" />
</intent-filter>
- 给你添加一个
onHoverListener
View
convertView.setOnHoverListener(new OnHoverListener() {
@Override
public boolean onHover(View v, MotionEvent event) {
Log.d("ListAdapter", "Hover: " + item);
return false;
}
});
它会起作用的.
这篇关于Galaxy S4 上的浮动触控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!