【发布时间】:2019-11-01 12:04:55
【问题描述】:
我的应用主题扩展自 AppCompat,但我想动态使用 Chip,但是当我动态添加 Chip 时应用崩溃并出现异常
This component requires that you specify a valid TextAppearance attribute. Update your app theme to inherit from Theme.MaterialComponents (or a descendant).
但是当我将应用程序主题扩展到 Material 时,应用程序不会崩溃并且过滤芯片工作正常,但我的问题是我不想从 Material 扩展主题,因为它会影响我的应用程序 UI,我该如何在这种情况下使用芯片?
编辑: 使用桥接,它可以避免崩溃,但是当我点击芯片时,它不会改变我被点击的芯片的外观
Chip chip = new Chip(getContext());
ChipDrawable chipDrawable = ChipDrawable.createFromAttributes(getContext(), null, 0, R.style.Widget_MaterialComponents_Chip_Filter);
chip.setChipDrawable(chipDrawable);
chip.setCheckable(true);
chip.setText(itemArrayList.get(i).getName());
binding.rvReport.addView(chip);
谢谢
【问题讨论】:
-
芯片(parent.context, null, R.style.Theme_MaterialComponents )
-
不工作应用程序崩溃
标签: java android material-components material-components-android android-chips