¿Cómo agregar el borde coloreado en cardview?
Soy nuevo en Android y esta es mi primera pregunta aquí.
Estoy tratando de añadir un borde vertical coloreado al principio de la tarjeta. ¿Cómo puedo lograrlo en xml? Intenté agregarlo con el textview vacío pero está estropeando encima del cardview entero sí mismo. Por favor, compruebe el enlace de la imagen que aparece a continuación, por ejemplo.
- Android: uso del diseño XML desde el almacenamiento interno
- Android: se centra en EditText después de la selección de Spinner
- "Unhandled Event Loop Exception" al hacer algo en Android XML
- Android: verifica la firma de XML
- Obtención de recursos de / res en dependencia
Frontera coloreada en Cardview
Activity_main.xml
<android.support.v7.widget.CardView android:layout_width="fill_parent" android:layout_height="wrap_content" card_view:contentPadding="16dp" card_view:cardElevation="2dp" card_view:cardCornerRadius="5dp"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView style="@style/Base.TextAppearance.AppCompat.Headline" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Title" /> <TextView style="@style/Base.TextAppearance.AppCompat.Body1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Content here" /> </LinearLayout> </android.support.v7.widget.CardView>
Muchas gracias
- Cómo crear una flecha que mira hacia la derecha usando xml formas en android?
- Mapa de bits de StateListDrawable y mosaico
- Disposición relativa de Android con pie de página pegajoso
- Androide. OnEditorAction nunca llamado
- Los colores de Android no funcionan en mi dispositivo físico
- XML Spinner atributos textAlignment = "derecho" API 16
- ¿Debería estar lleno el archivo xml del contenido de la copia de seguridad completa o no incluirlo en todos?
- AOSP AndroidManifest.xml
trata de hacerlo:
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:card_view="http://schemas.android.com/apk/res-auto" card_view:cardElevation="2dp" card_view:cardCornerRadius="5dp"> <FrameLayout android:background="#FF0000" android:layout_width="4dp" android:layout_height="match_parent"/> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="16dp" android:orientation="vertical"> <TextView style="@style/Base.TextAppearance.AppCompat.Headline" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Title" /> <TextView style="@style/Base.TextAppearance.AppCompat.Body1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Content here" /> </LinearLayout> </android.support.v7.widget.CardView>
Esto elimina el relleno del cardview y añade un FrameLayout con un color. A continuación, deberá corregir el relleno en LinearLayout y luego para los otros campos
Actualizar
Si desea conservar el radio de la esquina de la tarjeta cree card_edge.xml en una carpeta dibujable:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#F00" /> <size android:width="10dp"/> <padding android:bottom="0dp" android:left="0dp" android:right="0dp" android:top="0dp"/> <corners android:topLeftRadius="5dp" android:bottomLeftRadius="5dp" android:topRightRadius="0.1dp" android:bottomRightRadius="0.1dp"/> </shape>
Y en el diseño del marco use android:background="@drawable/card_edge"
Creo que esta solución puede no ser eficiente, pero sirve al propósito y añade flexibilidad con el ancho del borde.
<android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="40dp" android:layout_gravity="center" card_view:cardBackgroundColor="@color/some_color" card_view:cardCornerRadius="20dp" card_view:contentPadding="5dp"> <!-- Change it to customize the border width --> <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" card_view:cardCornerRadius="20dp" card_view:contentPadding="5dp"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <!-- Add your UI elements --> </RelativeLayout> </android.support.v7.widget.CardView> </android.support.v7.widget.CardView>
- "IllegalStateException: scrollview puede alojar sólo un hijo directo" en un LinearLayout añadiendo
- Onclick Listener para el botón Aceptar