callout-compose is a Jetpack Compose library that allows you to easily display callout
- minSdk version 27
Using callout-compose, you can display callouts anywhere you want.
Add the dependency below to your module's build.gradle file:
dependencies {
implementation("com.cybozu.callout.compose:callout-compose-core:0.0.2")
implementation("com.cybozu.callout.compose:callout-compose-material2:0.0.2")
}
dependencies {
implementation("com.cybozu.callout.compose:callout-compose-core:0.0.2")
implementation("com.cybozu.callout.compose:callout-compose-material3:0.0.2")
}
val calloutState = rememberCalloutState()
Text(
text = "Anchored Text",
modifier = Modifier
.anchoredCallout(
state = calloutState
)
)
Callout(
calloutState = calloutState,
verticalAlignment = CalloutAlignment.Vertical.Top,
horizontalAlignment = CalloutAlignment.Horizontal.End.outer()
) {
Text(text = "Hello, Callout!")
}
You can choose the following combinations for verticalAlignment and horizontalAlignment:
VerticalAlignment is divided into Inner and Outer:
- Inner: Top, Center, Bottom
- Outer: Top.outer(), Bottom.outer()
HorizontalAlignment is divided into Inner and Outer:
- Inner: Start, Center, End
- Outer: Start.outer(), End.outer()
The available combinations of VerticalAlignment and HorizontalAlignment is:
- Inner(Vertical) × Outer(Horizontal)
- Outer(Vertical) × Inner(Horizontal)
val calloutState = rememberCalloutState()
Text(
text = "Anchored Text",
modifier = Modifier
.anchoredCallout(
state = calloutState
)
)
Callout(
calloutState = calloutState,
verticalAlignment = CalloutAlignment.Vertical.Top,
horizontalAlignment = CalloutAlignment.Horizontal.End.outer()
) {
Text(text = "Hello, Callout!")
}
Top.outer() | Bottom.outer() | |
---|---|---|
Start | ![]() |
![]() |
Center | ![]() |
![]() |
End | ![]() |
![]() |
Top | Center | Bottom | |
---|---|---|---|
Start.outer() | ![]() |
![]() |
![]() |
End.outer() | ![]() |
![]() |
![]() |
This repository includes demonstration app.
if you use material2, open sample-app-material2 and Run it.
if you use material3, open sample-app-material3 and Run it.