Galaxy S4 上的浮动触控 [英] Floating Touch on Galaxy S4

查看:51
本文介绍了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,但是当 MotionEventMotionEvent.ACTION_HOVER_ENTERMotionEvent.ACTION_HOVER_EXITMotionEvent.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:

  1. 为清单中的 Activity 添加一个新的 Intent 过滤器到 com.sec.android.airview.HOVER:

<intent-filter>
<action android:name="com.sec.android.airview.HOVER" />
</intent-filter>

  1. 给你添加一个onHoverListener View

convertView.setOnHoverListener(new OnHoverListener() {
    @Override
    public boolean onHover(View v, MotionEvent event) {
        Log.d("ListAdapter", "Hover: " + item);
        return false;
    }
});

它会起作用的.

这篇关于Galaxy S4 上的浮动触控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆