gpt4 book ai didi

c# - xamarin 形式 : Couldn't change the background color of selected item on ListView

转载 作者:行者123 更新时间:2023-12-02 04:39:32 24 4
gpt4 key购买 nike

我正在尝试删除或至少更改 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>

当我选择 ListView 的任何项目时,颜色保持橙色。

enter image description here

有人知道这个问题的解决方法吗?

最佳答案

在 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>

关于c# - xamarin 形式 : Couldn't change the background color of selected item on ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44737782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com