[英]App Crashing with android material Chip Group with material 1.3.0
I have an issue with this我对此有疑问
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).
this is my xml code, I am trying to use chip group with a horizontal scroll view in relative layout and scroll view这是我的 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>
i was set my Parents Theme with我被设置为我的父母主题
<style name="AppTheme." parent="Theme.MaterialComponents.DayNight.NoActionBar">
and used dependencies with并使用依赖项
implementation 'com.google.android.material:material:1.3.0'
Try adding theme
individually to all your chips
which will be overriding the application or parent theme尝试将
theme
单独添加到将覆盖应用程序或父主题的所有chips
<com.google.android.material.chip.Chip
<!-- other props -->
android:theme="@style/Theme.MaterialComponents.Light />
Replace your AppTheme with this:将您的 AppTheme 替换为:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.