我想获取 Jetpack Compose 中按钮(或其他元素)的高度。你知道如何获得吗?
当我尝试使用 XML 在覆盖层中插入 Compose(在其他应用程序上绘制)时,出现以下异常:
java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from androidx.constraintlayout.widget.ConstraintLayout{d596746 V.E...... ......ID 0,0-0,0}
Run Code Online (Sandbox Code Playgroud)
但如果没有覆盖(在活动中),它可以正常工作。有谁知道如何解决吗?我已经将 AppCompat 库更新到 1.3.0
我的 XML 代码:
java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from androidx.constraintlayout.widget.ConstraintLayout{d596746 V.E...... ......ID 0,0-0,0}
Run Code Online (Sandbox Code Playgroud)
我的叠加代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black">
<androidx.compose.ui.platform.ComposeView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/compose_view"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud) 当我试图强制NavigationBar使用MaterialTheme.colorScheme.surface颜色时(请参阅材料 3 指南),应用程序的背景颜色和颜色NavigationBar不同。示例: 的颜色NavigationBar为#f1edf7,但背景颜色为#fffbfe。背景应用程序颜色也是MaterialTheme.colorScheme.surface如此。
android navigationbar android-jetpack-compose material-you android-jetpack-compose-material3
当我想通过 WifiManager.connectionInfo 获取有关当前 wifi 连接的信息时,我得到以下信息:
'connectionInfo 的吸气剂:WifiInfo!' 已弃用。在 Java 中已弃用
我该如何在 Android 12 中做到这一点?(只想获取RSSI)
在这个答案中,我弄错了波纹动画。您知道如何使用 Jetpack Compose 创建带有圆角的波纹吗?
使用默认波纹我有这个:

代码:
Card(shape = RoundedCornerShape(30.dp),
border = BorderStroke(width = 2.dp, color = buttonColor(LocalContext.current)),
backgroundColor = backColor(LocalContext.current),
modifier = Modifier
.fillMaxWidth()
.padding(10.dp)
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = rememberRipple(radius = 30.dp)
) { show = !show }
) { ... } //Show is animation of other element.
Run Code Online (Sandbox Code Playgroud)
//如果我放波纹半径200 dp(它是卡片的高度)波纹效果不正常。
我的 Jetpack Compose 活动加载速度太慢(大约 5 秒)。我有 3 个屏幕,带有 1 个惰性垂直网格和我的自定义底部导航。有人知道如何并行组成此屏幕或使加载活动更快吗?
我的代码:
@ExperimentalAnimationApi
@ExperimentalFoundationApi
@Composable
fun ComposeNavigation() {
val navController = rememberNavController()
ConstraintLayout(modifier = Modifier.fillMaxSize()) {
val (content, bottomSheet) = createRefs()
//Bottom is my custom bottom navigation
Bottom(navController, modifier = Modifier
.constrainAs(bottomSheet) {
start.linkTo(parent.start)
end.linkTo(parent.end)
bottom.linkTo(parent.bottom)
}
.fillMaxWidth())
Box(modifier = Modifier
.fillMaxWidth()
.constrainAs(content) {
start.linkTo(parent.start)
end.linkTo(parent.end)
}) {
NavHost(
navController = navController,
startDestination = "first_screen",
) {
composable("first_screen") {
FirstScreen(navController = navController)
}
composable("second_screen") {
SecondScreen(navController = navController)
}
composable("third_screen") { …Run Code Online (Sandbox Code Playgroud) android ×7
android-12 ×1
android-jetpack-compose-material3 ×1
android-jetpack-compose-text ×1
material-you ×1
wifimanager ×1