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>
- 给你添加一个
onHoverListenerView
convertView.setOnHoverListener(new OnHoverListener() {
@Override
public boolean onHover(View v, MotionEvent event) {
Log.d("ListAdapter", "Hover: " + item);
return false;
}
});
它会起作用的.
这篇关于Galaxy S4 上的浮动触控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Galaxy S4 上的浮动触控
基础教程推荐
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
