Le code MainActivity :
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void vibrate(View v){
v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}
}
Le code activity_main :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context="com.example.dianemoreau.haptic.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World 1!"
android:hapticFeedbackEnabled="true"
android:onClick="vibrate"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World 2!"
android:hapticFeedbackEnabled="true"
android:onClick="vibrate"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World 3!"
android:hapticFeedbackEnabled="true"
android:onClick="vibrate"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World 4!"
android:hapticFeedbackEnabled="true"
android:onClick="vibrate"/>
</LinearLayout>





