Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何更改ListView上选定项目的颜色?_C#_Android_Xamarin_Xamarin Forms - Fatal编程技术网

C# 如何更改ListView上选定项目的颜色?

C# 如何更改ListView上选定项目的颜色?,c#,android,xamarin,xamarin-forms,C#,Android,Xamarin,Xamarin Forms,我正在创建一个在ViewCell中包含一些简单项的ListView 当我选择其中一个项目时,它会变成橙色。当我点击并按住(打开上下文操作)时,它会变成白色 <ListView ItemsSource="{Binding Items}" HasUnevenRows="True"> <ListView.ItemTemplate> <DataTemplate> <ViewCell>

我正在创建一个在ViewCell中包含一些简单项的ListView

当我选择其中一个项目时,它会变成橙色。当我点击并按住(打开上下文操作)时,它会变成白色

<ListView ItemsSource="{Binding Items}" HasUnevenRows="True">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <ViewCell.ContextActions>
                    <MenuItem Text="Delete" />
                </ViewCell.ContextActions>
                <StackLayout Orientation="Horizontal" Padding="20">
                    <StackLayout HorizontalOptions="StartAndExpand">
                        <Label Text="{Binding Name}" FontSize="Large" FontAttributes="Bold" />
                        <Label Text="{Binding Description}" />
                    </StackLayout>
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>



如何定制这些颜色?

我发现我必须直接在Android上定制

要使用主题,我更改了Droid/Properties/AssemblyInfo.cs添加:

[assembly: Application(Theme = "@style/AppStyle.Light")]
我在上面创建了一些文件:

Droid\Resources\values

colors.xml
包含我的主题的颜色定义:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <color name="ListViewSelected">#96BCE3</color>
  <color name="ListViewHighlighted">#E39696</color>
</resources>
使用这些名称可以更改listview样式

android:colorPressedHighlight
android:colorLongPressedHighlight
android:colorFocusedHighlight
android:colorActivatedHighlight
android:activatedBackgroundIndicator
参考资料可在


派对迟到,但问题已在
收藏视图中解决



我花了很多时间寻找定制所选商品颜色的解决方案,但没有成功。在SO和Xamarin论坛上有一些变通办法,但没有一个让我高兴,或者根本不起作用。很长一段时间后,我决定在触发相应的事件后立即删除选定的项目状态,并更改项目的文本颜色,以标记选定的项目。@Wosi-hey,查看我的答案,可能对您有用:)可能重复Downvoted,因为它是一个仅适用于Android的解决方案,它没有回答问题。也许你的问题已经解决了,但我会回答我的iOS解决方案:我创建了一个
ViewCellRenderer
,覆盖了
UIKit.UITableViewCell GetCell
函数,并将
SelectionStyle
设置为
None
。如果有人感兴趣,我可以发送详细的示例代码。
android:colorPressedHighlight
android:colorLongPressedHighlight
android:colorFocusedHighlight
android:colorActivatedHighlight
android:activatedBackgroundIndicator