Android Studio 为什么我不能从我的主活动调用这个函数?

svmlkihl  于 2023-02-05  发布在  Android
关注(0)|答案(1)|浏览(146)

此函数位于我的android studio compose项目中的单独.kt文件中。
这是否与OptIn标记有关?因为没有此OptIn标记的所有其他功能都在工作。

@OptIn(ExperimentalWearMaterialApi::class)
@Composable
fun SwipeDetector(): Swiped? {

谢谢你。

uqdfh47h

uqdfh47h1#

从你的描述中听起来像是你在处理一个必须的选择加入。这意味着如果一个函数调用另一个具有所需OptIn注解的函数,这个函数也需要选择加入。这可以通过注解调用函数OptIn来解决,或者将函数所在的类标记为OptIn,或者将整个文件标记为OptIn

@OptIn(ExperimentalWearMaterialApi::class)
fun callingSwipeDetector(…

//or the whole class
@OptIn(ExperimentalWearMaterialApi::class)
class ContainingFunctionCallingSwipeDetector…

//or on top of the file that contains the function
@file:OptIn(ExperimentalWearMaterialApi::class)

相关问题