0

I have a Xamarin.Forms app with a ListView. When a listItem in pressed, on Android there is a ripple effect. It is a requirement to suppress that ripple.

I've tried it with a style in the Android project:

 <style name="MainTheme" parent="MainTheme.Base">
     <item name="android:listViewStyle">@style/ListViewStyle.Light</item>
 </style>

 <style name="ListViewStyle.Light" parent="android:style/Widget.ListView">
    <item name="android:listSelector">@drawable/actionbar_background_green</item>
 </style>

No luck - the style does not get picked up. I tried a custom ViewCell renderer:

protected override void OnCellPropertyChanged(object sender, PropertyChangedEventArgs args)
    {
        base.OnCellPropertyChanged(sender, args);

        if (args.PropertyName == "IsSelected")
        {
            _selected = !_selected;

            if (_selected)
            {
                _cellCore.SetBackgroundColor(Color.Transparent);
            }
            else
            {
                _cellCore.SetBackground(_unselectedBackground);
            }
        }
    }

That didn't work either. The ripple effect is still there and only when the ripple is over, the selected item picks up the color new background color.

The question concerns Xamarin.Forms, not Xamarin.Android nor Java.

Ketobomb
  • 2,108
  • 1
  • 17
  • 27

1 Answers1

1

This is an old question, but I hope this answer helps someone else looking for a solution. You can add a Frame to your ViewCell that fills it entirely and add an empty tap gesture recognizer to that Frame. That way the ViewCell won't detect any taps, so the ripple effect won't be triggered.

Layout example:

<ListView ItemsSource="{Binding ItemsSource}" HasUnevenRows="True" SelectionMode="None">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <AbsoluteLayout>
                    <Frame AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" BackgroundColor="Transparent">
                        <Frame.GestureRecognizers>
                            <TapGestureRecognizer/>
                        </Frame.GestureRecognizers>
                    </Frame>
                    <!-- Your controls !-->
                </AbsoluteLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
user13595734
  • 51
  • 2
  • 6