使用以下内容:
How to enable haptic feedback on button view
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
}
}
错误发生在以下行:myView.setOnClickListener(this);
按钮触觉反馈振动仅适用于个人设备,而不适用于从Google Play商店下载的设备。
类型View中的方法setOnClickListener(View.OnClickListener)不适用于参数(MainActivity)