6

This thing is driving me crazy. Here's how it works

1. everything is set as default

  • ripple effect works
  • list view item separator is visible

original state

2. white background added to the widget layout

  • ripple lost
  • list view item separator also gone
  • looks like list item style has been removed

white background

Here's the code

main widget layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              ...
              android:background="@android:color/white" -- this line only applies for case 2
              android:padding="@dimen/widget_padding">

    <TextView
        ...
        android:background="@color/primary"
        android:textColor="@android:color/white"/>

    <ListView
        ...
        android:drawSelectorOnTop="true""/>

    <TextView
        ...
        android:textColor="?android:attr/textColorSecondary"/>

</LinearLayout>

list item layout

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    android:id="@+id/widgetItem">

    <TextView
        ...
        android:textColor="@android:color/black"
        android:textSize="14sp"/>

    <TextView
        ...
        android:textColor="@color/negative_amount"
        android:textSize="16sp"
        android:textStyle="bold"/>

</RelativeLayout>

I've spent a day trying all possible combinations but nothing helped. And I don't get the fact that unrelated background change to some layout around the list view completely alters the behaviour. WTF?

I would like to solve it in the cleanest way possible - e.i. no hacking with custom selectors. This should work straight out of the box if possible.

user219882
  • 15,274
  • 23
  • 93
  • 138

1 Answers1

1

It looks like you're using a dark theme for your activity, so the ripple is white and thus not visible over a white background. The simplest solution is to use a light variant of the theme, which will cause the ripple to be black.

For example, if you're using an AppCompat theme, you can add this line to your ListView:

<ListView
    ...
    android:drawSelectorOnTop="true"
    style="@style/Theme.AppCompat.Light"/>

You can also apply this to a view hierarchy, e.g.:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      ...
      android:background="@android:color/white"
      android:padding="@dimen/widget_padding"
      android:theme="@style/Theme.AppCompat.Light">

This will cause the theme to be used in the LinearLayout and all of its child views.

Also, you can specify a theme activity-wide or even app-wide by adding android:theme attribute to the <activity> or <application> tag to your AndroidManifest.xml.

SpaceBison
  • 2,525
  • 1
  • 21
  • 38
  • I use Light theme in the application. But I tried your suggestion and set the theme to the list view / list view item to be sure and the behavior stayed the same - white widget background=no touch feedback at all, no widget background=ripple works fine (as I showed on screenshots). – user219882 Mar 13 '16 at 21:19
  • It might be that themes don't affect ripple colors of a `ListView`. If you don't find any sensible solution to your problem, maybe you should consider switching to `RecyclerView`? That way you'll have better control of the list's behavior and appearance. – SpaceBison Mar 14 '16 at 12:14