我正在创建一个 ListView,它在 ViewCell 中包含一些简单的项目。
当我选择其中一项时,它变成橙色。当我单击并按住(打开上下文操作)时,它变成白色...
<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>
styles.xml
包含主题设置:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="AppStyle.Light" 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>
</resources>
使用这些名称我可以更改 ListView 样式。
android:colorPressedHighlight
android:colorLongPressedHighlight
android:colorFocusedHighlight
android:colorActivatedHighlight
android:activatedBackgroundIndicator
可以在 developer.android.com R.attr 上找到引用资料
关于c# - 如何更改 ListView 上所选项目的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32490004/