Alright here is what you need..
Vibrate Animation
put these two xml files inside res/anim
folder
vibrate.xml
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="10"
android:duration="1000"
android:interpolator="@anim/cycle_5" />
cycle_5.xml
<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:cycles="5" />
Vibrating Phone
use these method to vibrate your phone for 500 milliseconds
public void shakeItBaby() {
int DURATION = 500; // you can change this according to your need
if (Build.VERSION.SDK_INT >= 26) {
((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(DURATION, VibrationEffect.DEFAULT_AMPLITUDE));
} else {
((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(DURATION);
}
}
and don't forget to put permission in menifest
<uses-permission android:name="android.permission.VIBRATE" />
Putting all together
now use them both wile validating your EditText
Animation vibrate = AnimationUtils.loadAnimation(this, R.anim.vibrate);
if (paytm_amt.getText().toString().trim().isEmpty()) {
paytm_num.setError("Please Enter PayTM Number");
paytm_num.startAnimation(vibrate);
shakeItBaby();
} else {
// do something
}
Happy Coding..