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 上的浮动触控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Galaxy S4 上的浮动触控


基础教程推荐
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01