我希望在按钮被点击时显示一个自定义提示。该提示应该在角落处呈圆形,并覆盖深色背景。到目前为止,我能够使用以下代码实现这一点:
Modifier.clickable(onClick = {}, indication = PressedIndication)
object PressedIndication : Indication {
private object DefaultIndicationInstance : IndicationInstance {
override fun ContentDrawScope.drawIndication(interactionState: InteractionState) {
drawContent()
if (interactionState.contains(Interaction.Pressed)) drawRoundRect(
cornerRadius = CornerRadius(4f, 4f), //<-- How to use dp values?
color = Color.Black.copy(
alpha = 0.3f
), size = size
)
}
}
override fun createInstance(): IndicationInstance {
return DefaultIndicationInstance
}
}
我可以使用drawRoundRect
和cornerRadius
来实现圆角,但是否有使用dp
值的方法?
注意:我不能使用clickable
和clip
,因为可点击区域与指示区域不完全匹配