I'm using a RecyclerView for a list. I've a found a really nice solution to give the list click feedback and ripple (on Lollipop).
Basically I'm giving my row layout the attribute:
android:background="?android:attr/selectableItemBackground"
And everything is fine, except that I need a different background color for my list (default state). How can I override just the basic state background (not clicked) giving it a different color?
This will give custom background color and default grey ripple effect:
android:background="#color/YourCustomColor"
android:foreground="?android:attr/selectableItemBackground"
You can try this: it helped me a lot, this way we can use the background we want and keep the great click feedback.
Wrap your row view inside a frame layout.
Are you using CardViews in your RecyclerView? If so, programmatically use .setCardBackgroundColor() in your holder to each CardView. Alternatively, you can wrap everything in a simple dummy FrameLayout (with an android:id) in the CardView, and programmatically change that layout's background when you bind the ViewHolders.
Related
I use Material transitions when switching between fragments, in this case a SharedZAxisTransition, but my problem is that if an image is wrapped inside a cardview, the corners of that cardview somehow dissapear as soon as the transition starts. image
I don't know why that is happening, i've been struggeling with this for a few days. Any ideas?
Okay I found the solution. I just needed to set a background color on the root layout and add transitionGroup="true" to the cardview, now it works.
I would like to know if it's possible to have the add/remove animations not overlap the divider like in the following video:
https://www.grokkingandroid.com/wordpress/wp-content/uploads/2014/08/recyclerview_animation.mp4?_=1
I am unsure as to how I can make the divider be bound to the item and not the view. Any help is useful.
Check the divider in SupportV7Demos app in AOSP. Basically, you should consider View's translateX/translateY properties when positioning your dividers.
I have a problem with an ExpandableListView in my Android application. I've set a custom background color but while scrolling the list the color changes to black untill the scrolling has stopped. Is that normal or can you change the "onScrollColor"?
I had this kind of problem and solved it using this property in my list XML android:cacheColorHint = "#00000000"
Make sure you use a ViewHolder for reuse of your Views inside your getView Method
like in this example:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html
the background to this is that Android trys to reuse the Views while scrolling and if you dont obey the Caching Rules (eg Using a ViewHolder like in the example) you have that described problem.
I hope, my issue would be clear for you from my question title. I have three linear layouts in each row of the list view. One linear layout contains an Imageview and the other two linear layout contains text views. These three linear layouts comprise my list view row. But, to my surprise, the listview default selection(orange colored) does not work when I move the trackball of mouse or when I select it from the phone.
Can anyone guide me resolve this issue.
Any help is appreciated.
Looking forward..
By default, the list selector is drawn behind the currently selected item. If your item layout has an opaque background, the selector cannot be seen.
Try making your list item background transparent.
Did you add a background color to your row's layouts? If so, that color will be the only color you see - even on touch events.
A row's background should really be set to a selectable drawable with different colors for different states like selected and unselected.
I have a simple ListView and on that ListView I have placed a number of custom defined Views. The CustomView has ImageView and two TextViews.
The CustomView also has a "stateful drawable" as background, so that the background image (a 9-patch) changes if you press the Row in the ListView. When pressing the Row, the background image changes to a Red-ish thing.
The problem is that when the background changes from the default greyish, all the Views in the CustomView (ImageView and TextViews) still have their greyish background and thus creates very ugly greay boxes on top of the now redish background.
What is the best way to solve that problem? I hoped that such things were handled automatically (as it is done in for example .NET), but I was wrong it seems.
I got it =)
You can use the color "transparent"
android:background="#android:color/transparent"
Set the Views with that color, and its all good =)