小编Ben*_*Tec的帖子

未使用内容填充参数

我最近开始使用 Jetpack Compose。我有以下可组合项:

@Composable
fun SearchScreen(navController: NavHostController) {
    Scaffold(
        topBar = { SearchBar() },
        content = {
            Column (
                modifier = Modifier.fillMaxSize()
            ) {
                // some nested Composables
            }
        }
    )
}
Run Code Online (Sandbox Code Playgroud)

但按原样使用此代码,其中的整个代码content = {...}都用红色下划线表示Jetpack Compose: Content padding parameter it is not used。我已经在这篇Stackoverflow 帖子中读到,实际上,PaddingValues只有在设置了 的情况下才在脚手架中提供bottomBar,这显然不是这里的情况。所以我不明白为什么我会收到这个错误。

注意:该应用程序实际上确实使用了 a BottomNavigation,但不在Composable我上面显示的范围内。难道这仍然以某种方式在这里传播吗?

android android-jetpack-compose jetpack-compose-navigation

108
推荐指数
3
解决办法
3万
查看次数

Android Studio 构建错误 -compileDebugJavaWithJavac 任务(当前目标是 1.8)和 kaptGenerateStubsDebugKotlin 任务(当前目标是 17)

在 Android Studio 中出现以下构建错误

compileDebugJavaWithJavac task (current target is 1.8) and kaptGenerateStubsDebugKotlin task (current target is 17) jvm target compatibility should be set to the same java version
Run Code Online (Sandbox Code Playgroud)

在 Android Studio 中构建项目的 kaptGenerateStubsDebugKotlin 步骤期间

我正在使用 Android Studio Giraffe | 2022.3.1 金丝雀3

下面是完整的堆栈跟踪

Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'kaptGenerateStubsDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
  Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

* Try:
> …
Run Code Online (Sandbox Code Playgroud)

android gradle kotlin android-studio android-gradle-plugin

100
推荐指数
6
解决办法
6万
查看次数

ConstraintLayout Flow帮助程序示例

我在一个博客条目中读到,在ConstraintLayout2.0.0中引入了一种创建视图流的方法。我真正想要实现的是:我有几个TextView彼此固定大小的。根据屏幕大小,一些TextView应当推入下一行。

大屏幕上有六个示例TextViews

[AAA] [BBB] [CCC] [DDD]

[EEE] [FFF]

在具有六个小屏幕的示例TextViews

[AAA] [BBB]

[CCC] [DDD]

[EEE] [FFF]

我已经看到了这个#1问题的提出使用FlexboxLayout,但有一个评论说,同样的事情现在可以使用来实现ConstraintLayout

任何人都可以给我一个例子,说明如何使用来实现所需的行为ConstraintLayout?我找不到关于此的任何说明。提前致谢。

xml layout android android-constraintlayout

7
推荐指数
1
解决办法
1436
查看次数

mutableStateOf 和 mutableStateListOf 有什么区别?

在使用存储在其中的 aViewModel和 a时List,我通常遵循以下方法:

var characteristics by mutableStateOf(listOf<Characteristic>())
Run Code Online (Sandbox Code Playgroud)

然后,我可以将数据分配给列表或修改它,并且 UI 将正确重构:

characteristics = issuesRepository.getCharacteristics()
characteristics = characteristics.plus(newCharacteristic)
Run Code Online (Sandbox Code Playgroud)

然而,我最近偶然发现了几种包含关键字 的方法mutableStateListOf(),然后将 List 分成两个单独的变量似乎是一种常见的做法,如下所示:

private val _characteristic = mutableStateListOf<Characteristic>()
val characteristic: List<Characteristic> = _characteristic
Run Code Online (Sandbox Code Playgroud)

这些方法有何不同,其中一种被认为是最佳实践还是一种更清洁的方法?

kotlin kotlin-android-extensions android-jetpack-compose

6
推荐指数
1
解决办法
2182
查看次数

Material3 MaterialToolbar 禁用滚动着色

我正在将我的应用程序迁移到Theme.Material3.*,发现MaterialToolbar一旦某些内容在其下方滚动,它就会以某种强调色突出显示。请参阅下面我提到的动画:

屏幕录制

但是,我不希望这种效果出现在我的应用程序中。但在阅读MaterialToolbar 文档时,似乎没有办法禁用或修改它,这让我很恼火。我在这里缺少什么?

重现行为的最小 XML 布局(以及使用Material3 主题):

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:liftOnScroll="true">

        <com.google.android.material.appbar.MaterialToolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:titleCentered="true"
            app:title="Welcome"
            app:layout_scrollFlags="noScroll" />

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
   
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Lorem ipsum dolor sit amet..." />

    </androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

感谢您的帮助。

android material-design android-toolbar material-components-android

1
推荐指数
1
解决办法
2250
查看次数