Trying to make some border around cardView
(androidx.cardview.widget.CardView
)
Here's the code:
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="273dp"
android:layout_height="118dp"
android:layout_marginStart="9dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="9dp"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:orientation="vertical"
app:cardCornerRadius="8dp"
android:background="@drawable/fix_border"
app:strokeColor="#dedede"
app:strokeWidth="3dp">
</androidx.cardview.widget.CardView>
Result:
Also tried to use a custom shape as a background (fix_border.xml
), doesn't work either.
fix_border.xml
:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="2dp"
android:color="#dedede" />
<!-- <solid android:color="#ffffff" />-->
<padding
android:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp" />
</shape>
Customized CardView First, add a CardView dependency to the application-level build. gradle file. Then create a drawable background for the cards. For that, create a new drawable resource file inside the drawable folder.
This field is deprecated.
MaterialCardView is a customizable component based on CardView from the Android Support Library. MaterialCardView provides all of the features of CardView , but adds attributes for customizing the stroke and uses an updated Material style by default.
Just use the Material Components Library and the MaterialCardView
which extends the androidx.cardview.widget.CardView
.
Something like:
<com.google.android.material.card.MaterialCardView
app:strokeColor="@color/primaryDarkColor"
app:strokeWidth="3dp"
../>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With