我目前无法仅使用 TabLayout 和 ViewPager 呈现活动。我收到此错误:
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>
我将 TabLayout 和 ViewPager 添加到一个空白的新布局中,但它们从未呈现过,即使在“连接”到片段之后也是如此。
努力改变
implementation 'com.google.android.material:material:1.8.0'
到 build.grable 中的implementation 'com.google.android.material:material:1.7.0'
。它对我有用
1.8.0版本好像有问题
其他材料设计示例 TabLaout 中的 TabItems 也有渲染问题。
降级到 1.7.0 工作正常。