11
Июн
2021

SelectableItemBackground под ImageView в MaterialCardView

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/cardView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:checkable="true"
    android:clickable="true"
    android:drawSelectorOnTop="false"
    android:contentDescription="@string/purpose"
    android:focusable="true"
    android:importantForAccessibility="auto"
    app:cardCornerRadius="30dp"
    app:cardElevation="1dp"
    app:cardUseCompatPadding="true"
    app:checkedIcon="@null"
    app:checkedIconMargin="@dimen/spacing_double">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/containerPurpose"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="@dimen/spacing_double"
            app:layout_constraintBottom_toTopOf="@+id/containerActions"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="1.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0">

            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/imagePurpose"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:adjustViewBounds="true"
                android:contentDescription="@string/image"
                android:scaleType="centerCrop"
                app:layout_constraintBottom_toTopOf="@+id/titlePurpose"
                app:layout_constraintDimensionRatio="1:1"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/circle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/spacing_double"
                android:layout_marginBottom="@dimen/spacing_double"
                android:gravity="center"
                android:text="@string/circle"
                android:textColor="@color/black"
                android:textSize="36sp"
                app:layout_constraintBottom_toBottomOf="@+id/imagePurpose"
                app:layout_constraintStart_toStartOf="@+id/imagePurpose" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/titlePurpose"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_marginStart="@dimen/spacing_double"
                android:layout_marginTop="@dimen/spacing_normal"
                android:layout_marginEnd="@dimen/spacing_double"
                android:singleLine="true"
                android:text="@string/title"
                android:textAppearance="?attr/textAppearanceHeadline5"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/imagePurpose" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/descriptionPurpose"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_marginStart="@dimen/spacing_double"
                android:layout_marginTop="@dimen/spacing_normal"
                android:layout_marginEnd="@dimen/spacing_double"
                android:linksClickable="true"
                android:text="@string/long_text"
                android:textAppearance="?attr/textAppearanceBody1"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/titlePurpose" />
        </androidx.constraintlayout.widget.ConstraintLayout>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/containerActions"
            android:layout_width="match_parent"
            android:layout_height="64dp"
            app:layout_constraintBottom_toTopOf="@+id/containerDates"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/containerPurpose">

            <View
                android:id="@+id/separatorActions"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/separatorActions"
                android:visibility="gone"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/textFavourite"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:layout_marginStart="@dimen/spacing_double"
                android:background="@drawable/button_circle_background"
                android:clickable="true"
                android:focusable="true"
                android:foreground="@drawable/fg_ripple_circle"
                android:gravity="center_vertical"
                android:paddingStart="@dimen/spacing_normal"
                android:paddingEnd="@dimen/spacing_normal"
                android:tooltipText="@string/add_to_favourite"
                app:drawableStartCompat="@drawable/ic_menu_unfavourite"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@+id/separatorActions"
                tools:ignore="UnusedAttribute" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/textTasks"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:layout_marginStart="@dimen/spacing_double"
                android:background="@drawable/button_circle_background"
                android:clickable="true"
                android:drawablePadding="@dimen/spacing_normal"
                android:focusable="true"
                android:foreground="@drawable/fg_ripple_circle"
                android:gravity="center_vertical"
                android:paddingStart="@dimen/spacing_double"
                android:paddingEnd="@dimen/spacing_double"
                android:text="@string/numbers"
                android:textAppearance="?attr/textAppearanceBody2"
                android:textColor="@color/item_bottom_date_color"
                android:textSize="18sp"
                android:tooltipText="@string/tasks"
                app:drawableStartCompat="@drawable/ic_done_all"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toEndOf="@+id/textFavourite"
                app:layout_constraintTop_toTopOf="@+id/separatorActions"
                tools:ignore="UnusedAttribute" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/textNotes"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:layout_marginStart="16dp"
                android:background="@drawable/button_circle_background"
                android:clickable="true"
                android:drawablePadding="@dimen/spacing_normal"
                android:focusable="true"
                android:foreground="@drawable/fg_ripple_circle"
                android:gravity="center_vertical"
                android:paddingStart="@dimen/spacing_double"
                android:paddingEnd="@dimen/spacing_double"
                android:text="@string/numbers"
                android:textAppearance="?attr/textAppearanceBody2"
                android:textColor="@color/item_bottom_date_color"
                android:textSize="18sp"
                android:tooltipText="@string/notes"
                app:drawableStartCompat="@drawable/ic_note"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toEndOf="@+id/textTasks"
                app:layout_constraintTop_toTopOf="@+id/separatorActions"
                tools:ignore="UnusedAttribute" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/textMenu"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:layout_marginEnd="@dimen/spacing_double"
                android:background="@drawable/button_circle_background"
                android:clickable="true"
                android:contentDescription="@string/open_menu"
                android:focusable="true"
                android:foreground="@drawable/fg_ripple_circle"
                android:gravity="center_vertical"
                android:paddingStart="@dimen/spacing_normal"
                android:paddingEnd="@dimen/spacing_normal"
                android:textAppearance="?attr/textAppearanceBody2"
                android:textColor="@color/item_bottom_date_color"
                android:textSize="18sp"
                android:tooltipText="@string/open_menu"
                app:drawableStartCompat="@drawable/ic_more_horizontal"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="@+id/separatorActions"
                tools:ignore="UnusedAttribute" />
        </androidx.constraintlayout.widget.ConstraintLayout>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/containerDates"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="@dimen/spacing_double"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/containerActions">

            <View
                android:id="@+id/separatorDates"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="@dimen/spacing_double"
                android:background="@color/separatorActions"
                app:layout_constraintBottom_toTopOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="parent" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/textDateCreate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/spacing_double"
                android:layout_marginTop="@dimen/spacing_double"
                android:layout_marginBottom="@dimen/spacing_double"
                android:contentDescription="@string/create_date"
                android:singleLine="true"
                android:text="@string/example_create_date"
                android:textAlignment="textStart"
                android:textAppearance="?attr/textAppearanceBody2"
                android:textColor="@color/item_bottom_date_color"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/separatorDates" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/textDateFinish"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/spacing_double"
                android:layout_marginEnd="@dimen/spacing_double"
                android:contentDescription="@string/finish_date"
                android:singleLine="true"
                android:text="@string/example_end_date"
                android:textAlignment="textEnd"
                android:textAppearance="?attr/textAppearanceBody2"
                android:textColor="@color/item_bottom_date_color"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/separatorDates" />
        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>

Добрый вечер. Вопрос собственно в том, как убрать смешивание цвета SelectableItemBackground с поверхности ImageView при Checked = true у MaterialCardView?

Источник: https://ru.stackoverflow.com/questions/1294013/selectableitembackground-%D0%BF%D0%BE%D0%B4-imageview-%D0%B2-materialcardview

Тебе может это понравится...

Добавить комментарий