Highlight selected cell with background image - android

I am trying to highlight touched cells of my listView. Because the cells have a backgroundimage set I use an onTouchListener for the View of the tableCell to change the ColorFilter.
As described here the onTouch Listener seems to conflict with a OnItemClickListener of a ListView.
So is there any easier way to highlight a cell with a backgroundimage?

You can setup a list selector property and a drawable file for the state_selected/pressed etc.

I figured out that StateListDrawables can also be created programatically, so I could use a generic approach for setting background pictures.

Related

Custom selectableItemBackground

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.

Changing Z-index of listview selector to be above row views

I have a standard list where the rows contain images and textviews.
I would like to have the ListView's default listSelector to show up at the highest Z-index. Currently, it shows the animation under/behind the images. I want it to show the listSelector animation on top of the images and TextView.
Is this possible without creating a dummy ImageView in the row itself?
As per freddieptf's comment, the solution is to set "drawSelectorOnTop" to true on the ListView.
http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:drawSelectorOnTop

ListView: intercept click event to adjust selector

I have a ListView with my own adapter, who uses a own layout.
It's basically a horizontal LinearLayout with an Image and a TextView
I have specified a selector for my ListView, which changes the background color.
Furthermore I want to apply a ImageColorFilter on the ImageView. If the background changes.
Is there a simple way to do it with the build in ListView selector behavior or must I attach my own OnTouchListener to my LinearLayout?
I guess there are two possibilities:
Disbale the ListView selector and write your own OnTouchListener and
handle the touch events.
Use android:drawSelectorOnTop="true" to draw the selector on top of your View instead of drawing in the background.

Android: Placing selector over View

OK so I have a GridView of selectable items. Now, I am fully aware of how to create custom selectors for items. The problem is that whenever an item in the GridView is pressed, the selector is completely blocked by the grid item.
Is there any way to make it so that the selector appears over my grid item view? An example of this can be seen in the ''Play Music'' app. When you select an album in the grid a semi-transparent orange overlay appears on the item to indicate that it is being pressed.
Any ideas on how I would approach this?
OK so the solution to this is stupidly simple. You just use the attribute android:drawSelectorOnTop="true" in the XML element corresponding to your AdapterView.

Android Listview - Default Selection not working

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.

Categories

Resources