我正在try 在我现有的androidtv应用程序中使用Jetpack Compose. 我需要做一个带有麦克风图标的按钮,如果对焦了,它会改变 colored颜色 .像这样^
无重点
聚焦
这是我的ComposeView
<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,
)
}
}
看起来不错,对吧?
问题是,当我试图专注于这个按钮时,焦点首先转到AndroidComposeView
项(根据我的GlobalFocusListener
).
只有我的第二个动作(点击,D-Pad导航)使我的内容变得集中.
所以,出于某种原因,内部AndroidComposeView
从我的Content
中偷走了注意力
有什么办法可以防止这种行为吗?我只需要专注于我的内容,而不是AndroidComposeView
个包装器.