【发布时间】:2020-02-26 20:31:33
【问题描述】:
Android Studio 3.6
在 xml 布局中我有这个:
<com.google.android.material.card.MaterialCardView
android:id="@+id/cardPaymentCardView"
style="@style/cardViewStyle"
android:layout_width="0dp"
android:layout_height="0dp"
app:checkedIcon="@drawable/ic_credit_card_outline_select"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
要打开/关闭检查状态,我使用它(在我的活动中)
dataBinding.cardPaymentCardView.isChecked = !dataBinding.cardPaymentCardView.isChecked
它工作正常。不错。
但我需要直接在 xml 中设置检查状态。像这样:
android:checked_state="true"
但我得到编译错误
【问题讨论】:
-
"卡片实现了 Checkable,没有提供切换到 android:checked_state 的默认方式。客户端必须调用 setChecked(boolean)。这会显示 app:checkedIcon 并更改覆盖颜色。"来自MaterialCardView documentation
标签: android material-design material-components-android materialcardview