【发布时间】:2021-02-13 07:56:45
【问题描述】:
我对此有疑问
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.truesight/com.truesight.MainActivity}: android.view.InflateException: Binary XML file line #27 in com.truesight:layout/activity_main: Binary XML file line #27 in com.truesight:layout/activity_main: Error inflating class com.google.android.material.chip.Chip
Caused by: android.view.InflateException: Binary XML file line #27 in com.truesight:layout/activity_main: Binary XML file line #27 in com.truesight:layout/activity_main: Error inflating class com.google.android.material.chip.Chip
Caused by: android.view.InflateException: Binary XML file line #27 in com.truesight:layout/activity_main: Error inflating class com.google.android.material.chip.Chip
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
这是我的 xml 代码,我正在尝试在相对布局和滚动视图中使用带有水平滚动视图的芯片组
<ScrollView 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"
android:fillViewport="true"
android:background="@drawable/grad_bg"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<com.google.android.material.chip.ChipGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:singleLine="true"
app:singleSelection="true">
<com.google.android.material.chip.Chip
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_marginBottom="8dp"
android:background="@drawable/et_bg"
android:padding="12dp"
android:text="Valorant"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="20sp" />
<com.google.android.material.chip.Chip
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_marginBottom="8dp"
android:background="@drawable/et_bg"
android:padding="12dp"
android:text="CS:GO"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="20sp" />
<com.google.android.material.chip.Chip
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_marginBottom="8dp"
android:background="@drawable/et_bg"
android:padding="12dp"
android:text="DotA 2"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="20sp" />
<com.google.android.material.chip.Chip
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_marginBottom="8dp"
android:background="@drawable/et_bg"
android:padding="12dp"
android:text="PUBG"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="20sp" />
<com.google.android.material.chip.Chip
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_marginBottom="8dp"
android:background="@drawable/et_bg"
android:padding="12dp"
android:text="Mobile Legends"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="20sp" />
</com.google.android.material.chip.ChipGroup>
</HorizontalScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bottom_nav"
app:itemBackground="@color/nav_color"
app:itemTextColor="@drawable/selector"
app:itemIconTint="@drawable/selector"
app:menu="@menu/menu_nav"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
我被设置为我的父母主题
<style name="AppTheme." parent="Theme.MaterialComponents.DayNight.NoActionBar">
并使用依赖项
implementation 'com.google.android.material:material:1.3.0'
【问题讨论】:
-
为什么要在主题名称后添加一个点:
AppTheme.?
标签: java android android-layout android-chips