android - CardView background color states not being respected -


in brief:

how can define color states of cardview's cardbackgroundcolor property (in listview layout, in case)?

(i using rc1 of android l developer preview, on phone 4.4 installed, , "com.android.support:cardview-v7:21.0.0-rc1" in build.gradle)

longer:

in cardview layout, set corner radius , background color of cardview via cardcornerradius , cardbackgroundcolor.

however, background color doesn't repect selected states, i.e. if list item pressed, example.

if, in inner view of cardview, set background colour, , associated states, respected, however, display on corners defined in cardview.

so, how can ensure states in cardview's cardbackgroundcolor respected?

here's color used cardbackgroundcolor, colour_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" />     <!-- below seen in cardview dispaly -->     <item android:color="@android:color/holo_blue_bright" /> </selector> 

and layout uses cardview:

<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"     >  <!-- if set background color below, overwrite our radius defined above --> <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> 

though not ideal, since edges not rounded, can add touch feedback cardview :

<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"     app:cardcornerradius="4dp"     android:clickable="true"     android:foreground="?android:attr/selectableitembackground">      //nested view ...  </android.support.v7.widget.cardview> 

adding android:foreground , android:clickable attributes cardview.

also has negative side effect in android:clickable attribute overrides clicklistener, , therefore clicklisteners don't triggered.

update

i have examples of cardview implementations

loop (https://github.com/lawloretienne/loop) - https://github.com/lawloretienne/loop/blob/master/app/src/main/res/layout/category_card.xml

quickreturn (https://github.com/lawloretienne/quickreturn) - https://github.com/lawloretienne/quickreturn/blob/master/sample/src/main/res/layout/activity_quick_return.xml

update 2

after more research have come solution cardviews on api versions including pre-lollipop.

https://medium.com/@etiennelawlor/layout-tips-for-pre-and-post-lollipop-bcb2e4cdd6b2#.9h0v1gmaw


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -