简体   繁体   中英

Xamarin: Context Action Selected Item Background Color

I have a ListView and a custom cell inside it. I added the context Menu and it works fine. The only problem is that when I long press an item in the list the selected item will have a white background on Android which is not visible so the user won't be able to see which item they are selecting. is there anay way to change that?

You can customize the color property directly on Android.

1.add the following colors in file colors.xml

<color name="ListViewSelected">#96BCE3</color>
<color name="ListViewHighlighted">#E39696</color>

2.add the following properties in file styles.xml

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

And my whole styles.xml is as follows:

  <?xml version="1.0" encoding="utf-8" ?>
<resources>

  <style name="MainTheme" parent="MainTheme.Base">
  </style>
  <!-- Base theme applied no matter what API -->
  <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
    <item name="windowNoTitle">true</item>
    <!--We will be using the toolbar so no need to show ActionBar-->
    <item name="windowActionBar">false</item>
    <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette -->
    <!-- colorPrimary is used for the default action bar background -->
    <item name="colorPrimary">#2196F3</item>
    <!-- colorPrimaryDark is used for the status bar -->
    <item name="colorPrimaryDark">#1976D2</item>
    <!-- colorAccent is used as the default value for colorControlActivated
         which is used to tint widgets -->
    <item name="colorAccent">#FF4081</item>
    <!-- You can also set colorControlNormal, colorControlActivated
         colorControlHighlight and colorSwitchThumbNormal. -->
    <item name="windowActionModeOverlay">true</item>

    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>

   

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

  <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#FF4081</item>
  </style>
</resources>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM