[英]Change Raduis CardView Background Color
我有一个带有半径和笔划的 CardView,但是当我以编程方式更改 CardView 背景时,半径和笔划丢失了,我希望新颜色留在笔划内。
这是我的卡片视图 xml
<com.google.android.material.card.MaterialCardView
android:id="@+id/answerOneTransport"
android:layout_width="148dp"
android:layout_height="60dp"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
app:cardBackgroundColor="#F7F7F7"
app:cardCornerRadius="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/quizzTransportViewPager"
app:strokeColor="#9890FF"
app:strokeWidth="1dp" >
<TextView
android:id="@+id/textAnswwerOneTransport"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Answer One"
android:layout_gravity="center"
android:fontFamily="@font/nunito"
android:textSize="20sp"
/>
</com.google.android.material.card.MaterialCardView>
这是我改变颜色的地方:
answerOneTransport.setOnClickListener {
answerOneTransport.setBackgroundColor(Color.GREEN)
}
您需要使用android:backgroundTint
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.