如何启用按钮查看触觉反馈 [英] How to enable haptic feedback on button view

查看:264
本文介绍了如何启用按钮查看触觉反馈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想触觉反馈添加到我的应用程序的按钮和控制它们编程显示按钮的状态(启用和禁用)。 默认的触觉反馈setter方法​​仅适用于长期preSS。我怎样才能使之成为简单的按钮点击工作。

I want to add haptic feedback to my application's buttons and control them programmatically to show button state (enabled and disabled). The default haptic feedback setter works only for long press. How can i make it work for simple button clicks.

和是有办法对像触摸事件触觉反馈动?

And is there a way to have haptic feedback on events like touch move?

推荐答案

下面是一个答案,尽管它可能不是最好的实现:

Here is an answer, though it might not be the best implementation:

import android.view.View;
import android.os.Vibrator;

public class Main extends Activity implements OnClickListener
{
    private View myView;
    private Vibrator myVib;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        myVib = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);

        //myView can be any type of view, button, etc.
        myView = (View) this.findViewById(R.id.myView);
        myView.setOnClickListener(this);
    }

    @Override
    public void onClick(View v)
    {
        myVib.vibrate(50);
        //add whatever you want after this
    }
}

不要忘了,你还需要将android.permission.VIBRATE权限添加到程序的清单。您可以通过添加下面的AndroidManifest.xml中文件,这样做的:

Don't forget, you also need to add the "android.permission.VIBRATE" permission to the program's manifest. You can do so by adding the following to the "AndroidManifest.xml" file:

<uses-permission android:name="android.permission.VIBRATE"></uses-permission>

我希望帮助。

I hope that helps.

这篇关于如何启用按钮查看触觉反馈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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