android - Adding the effects of a RippleDrawable and a StateListDrawable to a RecyclerView -
i'm working on app uses dual-pane layout on larger devices similar what's detailed here. summary of layout; 1 pane contains list of options while other display detailed information on option selected other pane.
right when option selected there ripple effect that's seen when selecting other elements (buttons, check boxes, etc) after animation completes element returns it's previous color. i'd retain highlight ripple after animation completes , i'm having trouble figuring out how accomplish this.
this how ripple background looks. focus
selector doesn't - couldn't figure out how give elements focus. i've tried using selected
selector happens immediately, overriding ripple.
<?xml version="1.0" encoding="utf-8"?> <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="?android:coloraccent"> <item android:id="@android:id/mask" android:drawable="@android:color/black" /> <item> <selector> <item android:state_focused="true" android:drawable="@color/accent" /> </selector> </item> </ripple>
to re-iterate, question this: is possible have both ripple effect followed highlighted selection, , if how?
this has preserved ripple animation me on selection.
with ripple drawable use:
<?xml version="1.0" encoding="utf-8"?> <item> <selector> <item android:state_selected="true" android:drawable="@color/selected_color" /> <item android:drawable="@color/normal_color" /> </selector> </item> </ripple>
on adapter, call sethasstableids(true)
, implement getitemid
return unique values representing rows.
when item selected, do:
viewholder oldviewholder = (viewholder) recyclerview.findviewholderforitemid(olditemid); oldviewholder.itemview.setselected(false); viewholder newviewholder = (viewholder) recyclerview.findviewholderforitemid(newitemid); newviewholder.itemview.setselected(true);
also in adapter:
@override public void onbindviewholder(viewholder viewholder, int position) { ... viewholder.itemview.setselected(isselected); ... }
on side note, focused selector used highlighting navigation on devices use d-pad tv , older phones.
Comments
Post a Comment