Shake to Color is a fun and simple Android app that changes the background color of the screen when the user shakes the device. It uses the accelerometer sensor to detect motion and responds instantly with a randomly generated color.
This project is built as an introduction to working with hardware sensors in Android. It demonstrates how user gestures like shaking can trigger fun and dynamic visual changes — making it both educational and interactive.
- 🎯 Detects shake motion using the built-in accelerometer.
- 🌈 Changes background to a random RGB color on each shake.
- ⚡ Lightweight and responsive with real-time updates.
- 👶 Beginner-friendly implementation using native Android APIs.
- The app registers a SensorEventListener for the accelerometer.
- It tracks the speed of movement by calculating the difference in acceleration values.
- If the movement speed exceeds a certain threshold, it:
- Generates a random color using RGB values.
- Sets it as the background color of the main layout.
shake-to-color/
├── app/
│ └── src/
│ └── main/
│ ├── java/com/example/shakeshake/MainActivity.java
│ └── res/layout/activity_main.xml
└── AndroidManifest.xml
- Java
- Android SDK
- SensorManager API
- Accelerometer Sensor
-
Clone the repository:
git clone https://github.com/harinandanmv/shake-to-color.git
-
Open the project in Android Studio.
-
Connect your Android device or start an emulator.
-
Run the app and shake your phone to see the magic!
Feel free to reach out on LinkedIn or check out more projects on GitHub.