A persistent floating button that puts your screen to sleep (locks it) instantly with one tap. Works on top of all other apps. Draggable. Snaps to screen edges.
Built for Android head units / car radios / car stereos (aftermarket double-DIN units, Android Auto boxes, etc.): their displays often stay at full brightness at night with no easy way to just turn the screen off, so this puts a one-tap "sleep" / screen-off button always on top.
Keywords: android screen lock, screen off button, car radio dimmer, head unit night mode, floating overlay button, android auto screen off, double-DIN screen lock, car stereo brightness fix.
Grab the latest APK from Releases — no need to build it yourself. Sideload it (enable "install from unknown sources" if prompted).
- Floating moon button – always visible, overlays every app
- Drag & snap – drag anywhere, snaps to left/right edge on release
- Tap to sleep – single tap locks/sleeps screen immediately
- Haptic feedback – subtle vibration confirms the tap
- Persistent service – survives app switching; notification with quick Stop action
- Auto-start on boot – if both permissions are already granted, the button comes back automatically after the head unit reboots
- Dark space UI – minimal setup screen
- Android 8.0+ (API 26+)
- Two one-time permissions (no root, no Device Admin):
- Draw Over Other Apps – for the floating overlay
- Accessibility Service – to call
lockScreen()system action
- Open Android Studio → File → Open → select the
SleepButtonfolder - Wait for Gradle sync to complete
- Connect your Android device (USB debugging on) or start an emulator
- Press Run ▶
cd SleepButton
./gradlew assembleDebug
# APK: app/build/outputs/apk/debug/app-debug.apk
adb install app/build/outputs/apk/debug/app-debug.apk- Grant "Draw Over Other Apps" → tap Grant → toggle the app on → back
- Grant Accessibility → tap Grant → find "Sleep Button – Screen Lock" → enable it → back
- Tap Start Floating Button
- The 🌙 button appears – tap it to sleep, drag it to move
app/src/main/
├── AndroidManifest.xml
├── java/com/sleepbutton/app/
│ ├── MainActivity.kt ← Setup & permission UI
│ ├── FloatingButtonService.kt ← Foreground service + overlay button
│ └── LockScreenService.kt ← Accessibility service (screen lock)
└── res/
├── layout/
│ ├── activity_main.xml
│ └── layout_float_button.xml
├── drawable/
│ ├── ic_sleep.xml ← Moon icon (vector)
│ └── bg_float_button.xml ← Circular button background
├── xml/
│ └── accessibility_service_config.xml
└── values/
├── strings.xml
└── themes.xml
This app uses Android's Accessibility Service API:
performGlobalAction(GLOBAL_ACTION_LOCK_SCREEN)This is the same mechanism used by many assistive apps to lock the screen without requiring Device Administrator privileges. No user data is accessed.
| What | Where |
|---|---|
| Button size | layout_float_button.xml – change 56dp |
| Button color | bg_float_button.xml – change #CC1A1A2E / #4FC3F7 |
| Starting position | FloatingButtonService.kt – change params.y = 300 |
| Disable snap-to-edge | Remove snapToEdge() call in ACTION_UP |
| Disable vibration | Remove vibrate() call in ACTION_UP |
GPL-3.0 – see LICENSE.