Android Studio Build.VERSION_CODES.R 和 Window.getInsetsController() 丢失

标签 android android-studio kotlin gradle

我正在学习 udemy 上的类(class),其中讲师要求使用以下代码。 An image showing the code that the instructor required

我尝试使用相同的代码,但遇到了多个错误。 这是当我输入相同代码时 android studio 的样子。

My code

首先,android studio无法识别该符号 Build.VERSION_CODES.R

当我将鼠标悬停在 android studio 中突出显示的文本上时,它会显示以下消息:

Uncessary; SDK_INT is never < 21

这毫无意义,因为首先Build.VERSION_CODES.R api 级别为 30,我的最低目标 api 级别为 21。 其次,即使我的 SDK_INT不能低于 21。 Build.VERSION_CODES 内的版本代码不应该改变。

android studio 显示的下一个错误是它无法解析 window.insetsController

Unresolved reference: insetsController

如果我浏览 Window 的源代码android studio 里面的类我可以看到 getInsetsController方法insetsController字段应该是换行的。我尝试直接使用该方法而不是 kotlin getter,并且 android studio 也无法识别该方法。

Android studio showing that Window.getInsetsController() cannot be found

android studio找不到的另一个字段是WindowInsets.Type ,我可以看到它存在于源代码中,但我无法访问它。

我的compileSdkVersion设置为29buildToolsVersion设置为"29.0.3" .

如果有人知道发生了什么,如果您能回答,我们将不胜感激。我尝试创建一个新项目并尝试相同的代码,但错误仍然存​​在。也许我使用的sdk坏了?但我的sdk是android studio自带的,所以我不确定。最近,我将 android studio 从 4.0 更新到了 4.1,这可能是问题所在吗?

最佳答案

My compileSdkVersion is set to 29

将其设置为30。 Android R (Android 11) 的 API 级别为 30。

始终将您的 compileSdkVersion 设置为最新的 Android 生产版本。

关于Android Studio Build.VERSION_CODES.R 和 Window.getInsetsController() 丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66402900/

相关文章:

java - 如何动态地将 fragment 添加到现有 fragment ?

android - 在 ScrollView 中使用 Listview

java - 如何在Java项目中使用Kotlin库?

android - 更新到 Android Studio 4.1 时出现 java.lang.AssertionError

types - 为什么 Kotlin 不支持无符号整数?

Java Lambda 到 Kotlin

android - 谷歌地图应用程序的新更新不显示我在 Android 中创建的标记

java - Android 中的 apache 的 HttpClient?

java - 在 WebView 中选择元素并获取详细信息

android - 如何检测 ImagePainter 何时使用 Jetpack Compose 从 Web 加载照片?