I m trying to use Jetpack Compose in my existing AndroidTV App. I need to make a button with microphone icon which will change its color if it s focused. Like this^
重点
重点
一、导 言
<androidx.compose.ui.platform.ComposeView
android:id="@+id/micBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
在这里,我把该守则一分为二。
binding.micBtn.setContent {
var buttonResId by remember { mutableStateOf(R.drawable.speech_recognition_button_unfocused) }
IconButton(
modifier = Modifier
.size(60.dp)
.onFocusChanged {
buttonResId = if (it.is重点) {
R.drawable.speech_recognition_button_focused
} else {
R.drawable.speech_recognition_button_unfocused
}
},
onClick = onClick,
) {
Icon(
painter = painterResource(id = buttonResId),
contentDescription = null,
tint = Color.Unspecified,
)
}
}
Looks good, right?
The problem is when I try to focus on this button focus first goes to AndroidComposeView
item (according to my GlobalFocusListener
).
And only my second action (click, D-Pad navigation) makes my content focused.
So, for some reason internal AndroidComposeView
steals focus from my Content
是否有办法防止这种行为? 我只需要关注我的内容,而不是<代码”。 AndersComposeView summaryper.