In short:
How can we determine the color states of the CardView cardBackgroundColor property (in this case, in the ListView layout)?
(I use RC1 Android L developer preview on a phone with 4.4 installed and "com.android.support:cardview-v7:21.0.0-rc1" in build.gradle)
longer:
In the CardView layout, we set the corner radius and background color of the CardView through cardCornerRadius and cardBackgroundColor.
However, the background color does not reflect the selected states, for example, if a list item is pressed, for example.
If in the CardView internal view you specify the background color and the associated states that are respected, however, it will be displayed at the angles you define in CardView.
So, how can we ensure state matching in CardView cardBackgroundColor?
Here is the color used for cardBackgroundColor, color_with_states.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:color="@android:color/holo_green_dark" /> <item android:state_focused="true" android:state_enabled="false" android:color="@android:color/holo_green_dark" /> <item android:state_focused="true" android:state_pressed="true" android:color="@android:color/holo_green_dark" /> <item android:state_focused="false" android:state_pressed="true" android:color="@android:color/holo_green_dark" /> <item android:state_focused="true" android:color="@android:color/holo_green_dark" /> <item android:color="@android:color/holo_blue_bright" /> </selector>
And the layout that CardView uses:
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cardview="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" cardview:cardCornerRadius="10dp" cardview:cardBackgroundColor="@color/colour_with_states" > <TextView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:text="Lorem ipsum" android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceListItem" android:background="@null" android:gravity="center_vertical" android:paddingTop="8dip" android:paddingBottom="8dip" android:paddingStart="8dip" android:paddingEnd="8dip" /> </android.support.v7.widget.CardView>
android android-cardview
newfivefour Aug 17 '14 at 19:36 2014-08-17 19:36
source share