在新的kotlin项目中,activity_main.xml中不允许使用android:id属性

在新的kotlin项目中,activity_main.xml中不允许使用android:id属性

问题描述:

我在与属性相关的Kotlin的新Android Studio项目中遇到错误: 此处不允许使用android:x属性"

I get errors in new Android Studio project in Kotlin connected with attributes: 'Attribute android:x is not allowed here"

文件:activity_main.xml

file: activity_main.xml

<?xml version="1.0" encoding="utf-8" ?>
<androidx.drawerlayout.widget.DrawerLayout xmlns="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://www.w3.org/1999/XSL/Transform"
    android:id="@+id/drawer_layout" #here
    android:layout_width="match_parent" #here
    android:layout_height="match_parent" #here
    android:fitsSystemWindows="true" #here
    tools:openDrawer="start"> #here

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent" #here
        android:layout_height="match_parent" /> #here

    <com.google.android.material.navigation.NavigationView #here
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</androidx.drawerlayout.widget.DrawerLayout>

尝试使用Gradle文件同步项目:File-> Sync project with Gradle files.

Try syncing project with Gradle files: File -> Sync project with Gradle files.