android material 芯片组 material 1.3.0 导致应用程序崩溃
App Crashing with android material Chip Group with material 1.3.0
我对此有疑问
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>
我的 Parents 主题设置为
<style name="AppTheme." parent="Theme.MaterialComponents.DayNight.NoActionBar">
并使用了
的依赖项
implementation 'com.google.android.material:material:1.3.0'
尝试将 theme
单独添加到所有 chips
中,这将覆盖应用程序或父主题
<com.google.android.material.chip.Chip
<!-- other props -->
android:theme="@style/Theme.MaterialComponents.Light />
将您的 AppTheme 替换为:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
我对此有疑问
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>
我的 Parents 主题设置为
<style name="AppTheme." parent="Theme.MaterialComponents.DayNight.NoActionBar">
并使用了
的依赖项implementation 'com.google.android.material:material:1.3.0'
尝试将 theme
单独添加到所有 chips
中,这将覆盖应用程序或父主题
<com.google.android.material.chip.Chip
<!-- other props -->
android:theme="@style/Theme.MaterialComponents.Light />
将您的 AppTheme 替换为:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">