android 如何在cardview的侧面设置颜色

0h4hbjxa  于 2023-04-28  发布在  Android
关注(0)|答案(2)|浏览(140)

我试图了解什么是最好的方式来设置颜色在一个侧面的CardView像这样

我的cardview看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/cardViewWe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:foreground="?attr/selectableItemBackground"
android:transitionName="cardTransition"
app:cardBackgroundColor="@drawable/selector"
app:cardElevation="2dp"

card_view:cardCornerRadius="8dp">

  <androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 .....
 .....
   </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
uxhixvfz

uxhixvfz1#

试试这边

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:cardCornerRadius="10dp"
    app:cardElevation="2dp"
    app:cardUseCompatPadding="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:orientation="horizontal">

        <View
            android:layout_width="5dp"
            android:layout_height="match_parent"
            android:background="@color/colorAccent" />

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:padding="10dp">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Nilesh Rathod" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Nilesh Rathod" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Nilesh Rathod" />

        </LinearLayout>
    </LinearLayout>

</android.support.v7.widget.CardView>

输出

ubbxdtey

ubbxdtey2#

如何寻找Jetpack Compose的答案

Card(
    modifier = Modifier.fillMaxSize().height(80.dp).padding(4.dp),
    colors = CardDefaults.cardColors(
        containerColor = Color.White,
        contentColor = Color.White)
    ) {
    Row(modifier = Modifier.fillMaxSize().padding(0.dp)) {
        Box(modifier = Modifier.height(80.dp).width(8.dp).padding(0.dp)) {
            Button(
                modifier = Modifier.height(80.dp).width(8.dp).padding(0.dp),
                onClick = { },
                colors = ButtonDefaults.buttonColors(
                    containerColor = Color.Red,
                    contentColor = Color.Red,
                ),
                shape = RoundedCornerShape(8.dp, 0.dp, 0.dp, 8.dp),
            ) { }
        }
        Text(modifier = Modifier.padding(8.dp), text = "String", color = Color.Black)
    }
}

相关问题