![](/img/trans.png)
[英]Change the Background Color of an ListView Item on Xamarin Forms
[英]xamarin forms: Couldn't change the background color of selected item on ListView
我正在尝试删除或至少更改ListView(主详细信息)上所选项目的颜色。
我没有看到任何更改所选项目的背景颜色的选项。
到目前为止,这是我所做的:
<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>
当我选择列表视图的任何项目时,颜色保持橙色。
有人知道解决方法吗?
在Android中,您可以转到Resources / Value / Style.xml文件,然后添加以下代码:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.