gpt4 book ai didi

java - App Crashing with android material Chip Group with material 1.3.0

转载 作者:行者123 更新时间:2023-12-04 23:57:38 28 4
gpt4 key购买 nike

我有一个问题

 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 中使用带有水平 ScrollView 的芯片组

<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>

我被设置为我的 parent 主题

<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 />

关于java - App Crashing with android material Chip Group with material 1.3.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66182972/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com