安卓工作室 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" />
要打开/关闭检查状态,我使用这个(在我的 Activity 中)
dataBinding.cardPaymentCardView.isChecked = !dataBinding.cardPaymentCardView.isChecked
而且它工作正常。不错。
但是我需要直接在xml中设置checked status。像这样:
android:checked_state="true"
但是编译出错
最佳答案
没有提供切换到检查状态的默认方式,客户端必须调用卡上的 setChecked(boolean)
支票卡
Cards implement Checkable interface. In the default style, @style/Widget.MaterialComponents.CardView, the checked state shows a checked icon and changes the overlay color. A default way of switching to checked state is not provided, clients have to call setChecked(boolean) on the card. Setter for an OnCheckedChangeListener is also provided.
关于android - MaterialCardView:无法在 xml 布局中设置选中状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58644056/