为什么Androidx元素不起作用?这里不允许元素

发布于 2025-01-31 18:33:11 字数 3546 浏览 3 评论 0 原文

我已经进行了一些更改以手动将应用迁移到Androidx,因为重构工具无法正常工作,之后。在我的 build.gradle 文件中更新了这些更改。一切正常,但是这样做:有一个资源文件不允许我使用 androidx 窗口小部件。在我的项目中,有一个重复的文件,其中一个更改可行,另一个更改则没有。其他文件,无论是否重复,都可以正常工作,并且该项目是同步,构建和启动的。

和错误文件。

所有元素中的错误:元素 com.google.android.material.appbar.appbar.appbarlayout 在这里不允许。我已经尝试清洁缓存并重新打开,并删除.IDEA文件夹,但仍无法正常工作。

我的问题:为什么所有这些文件都重复了?为什么我不能仅在这里使用小部件?

编辑: 我的.xml有来自Androidx和材料的资源

    <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    >

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    android:theme="@style/Theme.AppTheme.AppBarOverlay">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/Theme.AppTheme.PopupOverlay">

        <androidx.appcompat.widget.AppCompatSpinner
            android:id="@+id/spn_documento_evento"
            android:layout_width="match_parent"
            style="@style/SpinnerAppCompat"
            android:layout_height="match_parent">

        </androidx.appcompat.widget.AppCompatSpinner>

    </androidx.appcompat.widget.Toolbar>

    <include layout="@layout/item_search"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:paddingLeft="2dp">
        <include layout="@layout/item_results_clear" />
        <include layout="@layout/item_filters_activated"  />
    </LinearLayout>

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

<include layout="@layout/content_documentos" />

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/floating_new_document"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:alpha="0.7"
    android:layout_marginRight="@dimen/floating_margin"
    android:layout_marginBottom="70dp"
    android:src="@drawable/ic_add" />

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/floating_audit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|left"
    android:alpha="0.7"
    android:layout_marginLeft="@dimen/floating_margin"
    android:layout_marginBottom="70dp"
    android:src="@drawable/ic_audit" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

I've made some changes to migrate my App to AndroidX manually because the Refactor tool doesn't work properly, following this map file. Amoung those changes I've updated Firebase imports in my build.gradle file. Everything works fine but this: there's a resource file that doesn't allow me to use AndroidX widgets. There are duplicates files like that all along my project, in one of them this change works, in the other doesn't. The other files, duplicate or not, work fine and the project is sync, build and launched right.

enter image description here

And the error file.

enter image description here

The error in all elements: Element com.google.android.material.appbar.AppBarLayout is not allowed here. I've alreay try to clean cache and reopen, and to remove .idea folder, still not working.

My questions: why are all those files duplicated? Why I can't use the widgets only in here?

Edit:
My .xml's have resources from AndroidX and Material

    <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    >

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    android:theme="@style/Theme.AppTheme.AppBarOverlay">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/Theme.AppTheme.PopupOverlay">

        <androidx.appcompat.widget.AppCompatSpinner
            android:id="@+id/spn_documento_evento"
            android:layout_width="match_parent"
            style="@style/SpinnerAppCompat"
            android:layout_height="match_parent">

        </androidx.appcompat.widget.AppCompatSpinner>

    </androidx.appcompat.widget.Toolbar>

    <include layout="@layout/item_search"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal"
        android:paddingLeft="2dp">
        <include layout="@layout/item_results_clear" />
        <include layout="@layout/item_filters_activated"  />
    </LinearLayout>

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

<include layout="@layout/content_documentos" />

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/floating_new_document"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:alpha="0.7"
    android:layout_marginRight="@dimen/floating_margin"
    android:layout_marginBottom="70dp"
    android:src="@drawable/ic_add" />

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/floating_audit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|left"
    android:alpha="0.7"
    android:layout_marginLeft="@dimen/floating_margin"
    android:layout_marginBottom="70dp"
    android:src="@drawable/ic_audit" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心如狂蝶 2025-02-07 18:33:11

gradle.properties文件中添加以下内容

org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
android.nonTransitiveRClass=true

,然后重建项目

Add following in gradle.properties file

org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
android.nonTransitiveRClass=true

And then rebuild the project

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文