ListView Selected Item Background Color

Summary

Provide a simple API for specifying the background color to use for the selected item in a ListView. Currently, this is only achievable through custom renderers for each platform.

API Changes

Add a new BindableProperty to ListView named "SelectedItemBackgroundColor".

Code

ListView lv = new ListView();
lv.SelectedItemBackgroundColor = Color.Blue;

XAML

<ListView SelectedItemBackgroundColor="Blue"/>

Intended Use Case

Changing the selected item background color seems like a common use case of a ListView. Each app has it's own visual style so changing this color to match your app's style seems like functionality that Xamarin.Forms should support natively.

Tagged:

Open · Last Updated

Posts

  • GanesanVGGanesanVG INMember ✭✭

    @AndrewRoberts , You can use Syncfusion ListView. It has support to change the backgroundcolor of selected item by SelectionBackgroundColor property.

    https://help.syncfusion.com/xamarin/sflistview/selection#selection-background-color

    Note: Syncfusion controls is available for free through the community license program if you qualify (less than 1 million USD in revenue).

  • ThomasBurkhartThomasBurkhart DEMember ✭✭✭✭

    I would add that there are case where you don't want to have any highlighting of the selected Item. Today you have to use custom renderers for this. So the ability to set the SelectedBackground (Or Highlight) to transparent would be great)

  • PierceBogganPierceBoggan USForum Administrator, Xamarin Team, Developer Group Leader Xamurai
    edited January 2017

    I support this proposal. It's a property that I utilize in almost all of my Android and iOS apps, and would be extremely useful to have in Xamarin.Forms.

    The iOS UITableView uses UITableViewCellSelectionStyle has both a Default and None value, which definitely need to be represented in any implementation of this proposal. Possible values would be Default, None, or any Color value?

  • Andrew_RobertsAndrew_Roberts USMember ✭✭

    @PierceBoggan
    How would these values translate to Android and UWP? My thinking is only accept Color values. The default value on iOS would translate to UITableViewSelectedStyle.Default, but None seems equivalent to Color.Transparent so I'm not sure we need to accept all these values. Just my 2 cents.

  • PierceBogganPierceBoggan USForum Administrator, Xamarin Team, Developer Group Leader Xamurai
    edited January 2017

    This actually raises a good point. The scope of your proposal would be to change the background color of a selected cell. If we used the underlying None value, then the SelectedItem value would never change, which is actually altering the behavior of the ListView, which isn't what we want. I'm with you in using Color.Transparent instead :smile:

  • AdamMeaneyAdamMeaney USMember ✭✭✭✭✭

    @PierceBoggan I find myself in need of this feature.

    Would it be alright to give it a try? Or is it not likely to be approved anytime soon?

  • MIFMIF USMember ✭✭

    +1

  • AdamMeaneyAdamMeaney USMember ✭✭✭✭✭

    As an update, I was able to make this work on Android and iOS without too much work, but had issues with the ContextActions disabling selection so the color would get messed up.

    I wasn't too sure of where to go with that, so I abandoned work on it for now.

  • N_BauaN_Baua INMember ✭✭✭✭✭

    Yeah need this feature,
    Use-case: using List view as a dynamic menu container in sidebars navigation drawer (Especially Android) and many more such uses.

    Also would be nice if there is a support for Color.Transparent or a property exposed as SelectedItemBackgroundColor="None.

    Regards,
    N Baua

  • EmmanuelVazquezEmmanuelVazquez USMember ✭✭

    +1

  • ChaseFlorellChaseFlorell CAInsider, University mod

    Another reason for this would be that when a user activates a context menu on Android, it helps to know which list item is being handled by the context menu above.

    This in and of itself is the reason I am stuck with the Telerik ListView for context menus (which I hate on Android).

  • AceCoderLauraAceCoderLaura AUMember ✭✭

    +1

  • +1

    Need this so much.
    Changing the list view using android layout, or theme is very annoying. It applies to the whole activity.

    While i need 1 color for my menu. and different color for other scenario. Some i don't even want to set background color.
    Unselecting the list using "listView.SelectedItem = null;" doesn't really works well. It disable the highlight on click, but when u hold it, if you got menu item for your list item, the highlight will still be there.

  • LouisBeaumontLouisBeaumont Member ✭✭

    +1

  • GiampaoloGabbaGiampaoloGabba USMember ✭✭✭

    There is this pull request https://github.com/xamarin/Xamarin.Forms/pull/2050 planned for Vnext+1

    Maybe in 3-4 months we will be able to change the backgroundcolor :)

Sign In or Register to comment.