gpt4 book ai didi

android - Jetpack Compose State List Drawable 等价物

转载 作者:行者123 更新时间:2023-12-04 15:57:21 24 4
gpt4 key购买 nike

获得 StateListDrawable 功能的最佳方法是什么?在 Jetpack Compose 中?

最佳答案

您可以使用 InteractionSource 更改组件在不同状态下的显示方式,例如按下、拖动或聚焦组件时。
就像是:

val interactionSource = remember { MutableInteractionSource() }
val isFocused by interactionSource.collectIsFocusedAsState()

//Define the textColor, the icon and the iconTint if the field is focused or not
val textColor = if (isFocused) Color.Black else Color.Red
val icon = if (isFocused) Icons.Filled.Add else Icons.Filled.Share
val iconTint = if (isFocused) Color.Black else Color.Red

TextField(
value = text,
onValueChange = {text = it},
interactionSource = interactionSource,
leadingIcon = {Icon( icon ,"contentDescription")},
colors = TextFieldDefaults.textFieldColors(
textColor = textColor,
leadingIconColor = iconTint
),
)
enter image description here
enter image description here
或者
val isPressed by interactionSource.collectIsPressedAsState()
val backgroundColor = if (isPressed) Color.Blue else Color.Red

Button(
interactionSource = interactionSource,
colors = ButtonDefaults.buttonColors(backgroundColor= backgroundColor),
onClick = {}
){
Text("Button")
}

关于android - Jetpack Compose State List Drawable 等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67339712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com