Reputation: 1023
I'm trying to remove or at least change the color of the selected item on a ListView (Master Detail).
I didn't see any option to change the background color of the selected item.
Here is what I have done so far:
<ListView ItemsSource="{Binding MenuItems}"
HasUnevenRows="True"
RowHeight="50"
>
<ListView.Behaviors>
<e:EventToCommandBehavior EventName="ItemTapped"
Command="{Binding NavigateCommand}"
EventArgsParameterPath="Item.ViewName">
</e:EventToCommandBehavior>
</ListView.Behaviors>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout VerticalOptions="Center" HorizontalOptions="FillAndExpand"
Orientation="Horizontal"
Padding="20,0,0,0"
Spacing="10"
HeightRequest="50">
<Image Source="{Binding Icon}"
WidthRequest="40"
HeightRequest="40"
VerticalOptions="Center" />
<Label Text="{Binding Title}"
FontSize="Medium"
VerticalOptions="Center"
TextColor="Black"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
When I select any item of the listview, the color keeps orange.
Does anybody know a workaround for this?
Upvotes: 2
Views: 2607
Reputation: 707
In Android, you can do that going to your Resources/Value/Style.xml file, and add this code:
<resources>
<style name="MyTheme" parent="android:style/Theme.Material.Light.DarkActionBar">
<item name="android:colorPressedHighlight">@color/ListViewSelected</item>
<item name="android:colorLongPressedHighlight">@color/ListViewHighlighted</item>
<item name="android:colorFocusedHighlight">@color/ListViewSelected</item>
<item name="android:colorActivatedHighlight">@color/ListViewSelected</item>
<item name="android:activatedBackgroundIndicator">@color/ListViewSelected</item>
</style>
<color name="ListViewSelected">#96BCE3</color>
<color name="ListViewHighlighted">#E39696</color>
</resources>
Upvotes: 9