【发布时间】:2021-07-04 19:38:42
【问题描述】:
我通过扩展 XML 布局从 XML 数据动态创建卡片列表。此布局有一个带有虚拟值的按钮来抑制 IDE 的警告,我想根据该 XML 资源中的数据设置标签和前导图标。
我可以设置标签,但是我找不到改变app:icon属性的方法。
layout.xml:
...
<Button
android:id="@+id/listItemAction"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="@string/misc_load" <!-- dummy value -->
app:icon="@drawable/ic_round_help_24" <!-- dummy value --> />
...
Adapter.java:
...
viewHolder.action.setText(list.get(position).label); // it works
viewHolder.action.setIcon(list.get(position).icon); // there is no such method
...
【问题讨论】:
标签: android android-button material-components-android