android-appbarlayout - 迁移项目中的androidx appbarlayout问题

标签 android-appbarlayout androidx

我最近将我的项目重构为 androidx。但现在它有一个致命的异常。当我运行项目时,我遇到了 coordinatorlayout 和 appbarLayout 的错误,并且与 androidx 不兼容。我想我必须为 AppBarLayout 使用 androidx 替代方案,但我搜索它并找不到任何替代方案。

android.view.InflateException: Binary XML file line #36: Could not inflate Behavior subclass android.support.design.widget.AppBarLayout$ScrollingViewBehavior
Caused by: java.lang.RuntimeException: Could not inflate Behavior subclass android.support.design.widget.AppBarLayout$ScrollingViewBehavior

这是我的 xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">


<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appbar"
    android:fitsSystemWindows="true"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <com.google.android.material.appbar.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:toolbarId="@+id/toolbar"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:layout_scrollInterpolator="@android:anim/decelerate_interpolator"
        app:contentScrim="?attr/colorPrimary">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/allAdsMain_recyclerView_mainCategories"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

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

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".all_ad_main" >

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/allAdsMain_recyclerView_ads"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

<Button
    android:id="@+id/allAdsMain_button_adRegister"
    android:layout_width="140dp"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|center"
    android:layout_marginBottom="5dp"
    android:background="@drawable/roundshapebtn"
    android:text="@string/call_for_price"
    android:textColor="@color/white"
    android:textDirection="rtl"
    android:textSize="24sp"
    app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

最佳答案

您仍然在 NestedScrollView 下引用支持库依赖项。

变化:

app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"

app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"

您已经在 CoordinatorLayout 中使用它。下次遇到此类问题时,您可以在尝试创建(在这种情况下)AppBarLayout 并检查 Android Studio 想要导入的版本的包时使用 Android Studio 中的完整代码。如果您的依赖项设置正确,则应该只有 androidx 选项,

关于android-appbarlayout - 迁移项目中的androidx appbarlayout问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54854645/

相关文章:

android - 带有 appbar_scrolling_behaviour 的 appbar 下方的 BottomSheet

android-recyclerview - 如何防止 AppBarLayout 展开?

android - Android 中带有视差效果的 RecyclerView 上面的内容

android - 如何在整个主题中更改 AppBarLayout 的样式?

java - 如何为每个不同的 fragment 设置操作栏

android - 如何使用新的 Android-X API 从当前的 PreferenceFragment 打开一个新的 PreferenceFragment?

android - 将项目迁移到 androidx 后,EditTextPreference 不显示数字键盘

Android X 向后兼容性

android - Firebase 性能监控库与作为签名 jar 分发的库不兼容

android - 无法解析 : support-v4