AndroidX 中的 DrawerLayout 丢失了吗?

DrawerLayout in AndroidX is Missing?

我在我的应用程序中使用 DrawerLayout 和汉堡包菜单。我将我的应用程序迁移到 Androidx。一切似乎都是正确的,但 DrawerLayout。它不知道 DrawerLayout Class。

我必须做什么?

A​​ndroidX 有 its implementation of DrawerLayout.

implementation "androidx.drawerlayout:drawerlayout:1.0.0" 添加到模块的依赖项中(您可以检查 Google's Maven repository catalog 以确认可用版本)。

您应该将 xml 中的 drawerlayout 替换为下面的行

androidx.drawerlayout.widget.DrawerLayout

在您的 build.gradle 文件中添加 implementation "androidx.drawerlayout:drawerlayout:1.0.0",然后在要使用抽屉布局的布局文件中,更改 <androidx.core.widget.DrawerLayout 标记为 <androidx.drawerlayout.widget.DrawerLayout.

  1. 第一步:实施"androidx.drawerlayout:drawerlayout:1.0.0"

  2. 在布局顶部添加:< androidx.drawerlayout.widget.DrawerLayout >

  3. 必须以结束标签结束:< /androidx.drawerlayout.widget.DrawerLayout >