Trevi Awater Trevi Awater - 1 year ago 532
Android Question

Xamarin.Forms untappable ListView (remove selection ripple effect)

I have a ListView with a custom ViewCell that displays articles. However when you select a item, it shows the material design ripple/selection effect.

Ripple effect


<ListView HasUnevenRows="True" ItemsSource="{Binding NewsArticles}" IsPullToRefreshEnabled="True">
<StackLayout Padding="10">
<Label Text="{Binding Title}" HorizontalOptions="Center" FontAttributes="Bold" />
<Image Source="{Binding ImageUrl}" IsVisible="{Binding HasImage}" />
<Label Text="{Binding Content}"></Label>

How do I remove the ripple effect?


After doing some research I found the RepeaterView in the XLabs library. This works if you wrap it in a ScrollView although it takes away a lot of the neat ListView mechanics such as refreshing. It also doesn't support changes to the ItemSource from an external thread. Still looking for other solutions since I know this is possible in native Android.

Answer Source

So after a long, long time we figured it out, you can accomplish it with a custom renderer. Here is how,

First, create a file called no_selector.xml and place it in the Resources/layouts folder (the packaging properties must be set to AndroidResource).

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="">
  <item android:state_window_focused="false" android:drawable="@android:color/transparent"/>

After that create a custom renderer for the ListView component,

[assembly: ExportRenderer (typeof(ListView), typeof(NoRippleListViewRenderer))]
namespace Your.Own.Namespace
    public class NoRippleListViewRenderer : ListViewRenderer
        protected override void OnElementChanged (ElementChangedEventArgs<ListView> e)
            base.OnElementChanged (e);
            Control.SetSelector (Resource.Layout.no_selector);

If the no_selector file can't be found rebuild your project!

Be aware of the fact that this removes the ripple for all the ListViews in your application. If you only want it to target a couple you can change the first type on the ExportRenderer attribute (this does require you to make a separate class that extends ListView).

A sample can be found here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download