我正在尝试做出一个有多种选择的芯片选择。就我而言,我将有动态选择,因此我必须动态创建芯片。我成功地动态创建了它。但由于多重选择需要一个名为style="@style/Widget.MaterialComponents.Chip.Filter"
我可以在 XML 中传递它,但不能在 kotlin 代码中传递。
我尝试这样做但没有成功:
val chip = Chip(chapManager.context, null, android.widget.Filter)
它说:Classifier 'Filter' does not have a companion object, and thus must be initialized here
其他一切都工作正常,只是我无法将风格传递给我的芯片。
您可以定义单独的布局Chip
并设置您想要的所有属性XML
,然后膨胀布局。
val chip = layoutInflater.inflate(R.layout.chip_layout, view!!.parent.parent as ViewGroup, false) as Chip
芯片布局.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.chip.Chip xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/chipTextAppearance"
android:textColor="@android:color/black" />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)