Global Floating Window Framework based on Jetpack Compose
- Describe the floating window UI with Compose code.
ViewModelsupport inside the floating window.- Draggable floating windows that stay on screen.
- Dialog components that show from an application context.
The library requires Android 7.0 (API level 24) or newer.
Add the JitPack repository to settings.gradle.kts:
dependencyResolutionManagement {
repositories {
maven { url = uri("https://jitpack.io") }
}
}Add the dependency:
dependencies {
implementation("com.github.ArthurKun21:compose-overlay-window:<tag>")
}Add to AndroidManifest.xml:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />The user must also grant this permission in system settings. Check it with checkOverlayPermission(context), and open the settings screen with requestOverlayPermission(context).
Use ComposeFloatingWindow to show a floating window from an activity:
val floatingWindow = ComposeFloatingWindow(applicationContext)
floatingWindow.setContent {
FloatingActionButton(
modifier = Modifier.dragFloatingWindow(),
onClick = {
// Handle tap
},
) {
Icon(Icons.Filled.Call, "Call")
}
}
if (checkOverlayPermission(applicationContext)) {
floatingWindow.show()
} else {
requestOverlayPermission(this)
}Use ComposeServiceFloatingWindow to show a floating window from a service. The service content needs dragServiceFloatingWindow as the drag modifier:
val floatingWindow = ComposeServiceFloatingWindow(applicationContext)
floatingWindow.setContent {
FloatingActionButton(
modifier = Modifier.dragServiceFloatingWindow(),
onClick = {
// Handle tap
},
) {
Icon(Icons.Filled.Call, "Call")
}
}
if (checkOverlayPermission(applicationContext)) {
floatingWindow.show()
} else {
requestOverlayPermission(this)
}The documentation site has the full usage guide, examples, and API reference.
The sample apps in this repository show complete setups:
samples/app-activitysamples/keyboard-usagesamples/fullscreen-dialogsamples/service-hilt
Apache License 2.0
