Android compose: Popup

Andres Sandoval
2 min readAug 15, 2024

Add clickable text inside popup

// Privacy policy button
val context = LocalContext.current
var showPopup by remember { mutableStateOf(false) }



Button(
onClick = {
showPopup = true
Toast.makeText(context, "Privacy Policy", Toast.LENGTH_SHORT).show()
}) {


Text(text = "Privacy Policy")
Icon(imageVector = Icons.Filled.Info, contentDescription = null)
}
if (showPopup) {
Popup(
alignment = Alignment.TopCenter,
properties = PopupProperties(
excludeFromSystemGesture = true,
),
onDismissRequest = { showPopup = false }
) {
Box(
Modifier
.width(200.dp)
.height(300.dp)
.background(Color.White)
.border(1.dp, Color.Black)
.clip(RoundedCornerShape(4.dp)),
contentAlignment = Alignment.Center
) {
PrivacyPolicyText(context)
}
}
}

Create the method “PrivacyPolicyText” to show the clickable text

@Composable
fun PrivacyPolicyText(context: Context) {
val annotatedString = buildAnnotatedString {
append(" Open privacy ")


pushStringAnnotation(
tag = "policy",
annotation = "https://github.com/AndreSand/myimportantdates.github.io/blob/main/MIDPrivacyPolicy.html"
)
withStyle(style = SpanStyle(color = Color.Blue)) {
append("policy")
}
pop()
}


ClickableText(
text = annotatedString,
style = MaterialTheme.typography.body1,
onClick = {…

--

--

No responses yet