Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms ListView: Set the highlight color of a tapped item

Using Xamarin.Forms, how can I define the highlight/background color of a selected/tapped ListView item?

(My list has a black background and white text color, so the default highlight color on iOS is too bright. In contrast, on Android there is no highlighting at all - up to a subtle horizontal gray line.)

Example: (left: iOS, right: Android; while pressing "Barn2")

like image 228
Falko Avatar asked Sep 17 '14 07:09

Falko


1 Answers

In Android simply edit your styles.xml file under Resources\values adding this:

<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> 
like image 164
mfranc28 Avatar answered Sep 19 '22 19:09

mfranc28