In this blog, I will show you how can we aware the users for the wrong input or something went wrong. There are simple two way to alert your users or customer for the wrong input.
- Vibrate your Device
- Shake the Views or text
Vibrate Your Device
Step 1: Create the object for the Vibrator class,
1 private Vibrator vibrateObject;
Step 2: Below is the block of code for which vibrate the device for the 200 millisecond,
123 vibrateObject = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);// Vibrate for 200 millisecondsvibrateObject.vibrate(200);
Step 3: Add permission in Manifest.xml
1 <uses-permission android:name="android.permission.VIBRATE" />
Shake the View or text
Step 1: Create your shake error file,
123456 <?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android"android:duration="300"android:fromXDelta="0"android:interpolator="@anim/cycle_2"android:toXDelta="20" />
Step 2: Create the Interpolator,
123 <?xml version="1.0" encoding="utf-8"?><cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"android:cycles="2" />
Step 3: Apply on Views or text which you want to Shake or wobble,
12 findViewById(R.id.textView).startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.shake_error));findViewById(R.id.simpleView).startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.shake_error));
If you have any doubt on this blog, please ask in comments. And stay updated and stay super.