簡體   English   中英

xamarin形式:無法更改ListView上所選項目的背景顏色

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM