Android: CardView foreground using databinding

Viewed 2102

I'm trying to fill my RecyclerView with CardViews, the CardViews use Android databinding to set Attributes like Texts in TextViews. On Items that aren't finished jet I want to add a greyish overlay. But unfortunately the foreground android:foreground="@{viewModel.getState != State.FINISHED? @color/gray_transparent54 : null}"> is not applied. On the other hand, if I force the foreground color android:foreground="@grey_transparent54">, it works it is.

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <data class="ListItemBinder">
        <import type="myProject.State"/>
        <import type="android.view.View"/>
        <variable
            name="viewModel"
            type="myProject.ListItemViewModel"/>
    </data>

    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        card_view:cardCornerRadius="4dp"
        android:foreground="@{viewModel.getState != State.FINISHED? @color/gray_transparent54 : null}">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@{viewModel.getName}"
                tools:text="Name"
                android:textColor="@color/color_text_primary"
                android:textSize="24sp"/>
    </android.support.v7.widget.CardView>
</layout>

Thanks in advance.

1 Answers
Related