TabLayout 和 ViewHolder 的渲染问题

Mac*_*her 3 xml android android-layout android-design-library android-tablayout

我目前无法仅使用 TabLayout 和 ViewPager 渲染 am 活动。我收到此错误:

Style ResourceReference{namespace=apk/res-auto, type=attr, name=textAppearanceButton} is not of type STYLE (instead attr)

从以下代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".CompoundInterest">

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="409dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="86dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <com.google.android.material.tabs.TabItem
            android:id="@+id/tabAbout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="About" />

        <com.google.android.material.tabs.TabItem
            android:id="@+id/tabCalculator"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Calculator" />

    </com.google.android.material.tabs.TabLayout>

    <androidx.viewpager.widget.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tabLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

我将 TabLayout 和 ViewPager 添加到一个空白的新布局中,即使在“连接”到片段之后,它们也从未呈现。

小智 9

转到Android视图,找到Gradle Scripts-build.gralde(Module :App)然后编辑它。改变

implementation 'com.google.android.material:material:1.9.0'

implementation 'com.google.android.material:material:1.7.0'

最后点击Sync Project with Gradle Files,稍等一下就可以了。