Hi,
I have a Xamarin.Forms with only an Android Project. I was trying to change the default Android style but unfortunatelly without success.
I want to change the Listview color for select, focus and press events, which is orange.
I am using Visual Studio 2017 (15.5.4 version) and I can´t find a tutorial to do that in this version... I have found many tutorials to do that on a native Android project, which is not taking effect.
I have did that:
- created a xml file with a selector, like that:
<?xml version="1.0" encoding="utf-8" ?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:color="#FF000000" /> <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:color="#FF000000" /> </selector>
- changed the style.xml file, including a new style tag like that:
``
<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">#2196F3</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:listViewStyle">@style/ListViewStyle.Light</item>
</style>
<style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#FF4081</item>
</style>
** <style name="ListViewStyle.Light" parent="android:style/Widget.ListView">
<!--<item name="background">@color/list_row_default_bg</item>-->
<item name="android:divider">@color/divider</item>
<item name="android:dividerHeight">2dp</item>
<!--<item name="android:listSelector">@color/list_row_selected_bg</item>-->
<item name="background">@drawable/item_background_selector</item>
</style>**
</resources>
included attributes in the Listview control:
<ListView ItemsSource="{Binding FaturasCollection}" RowHeight="150" HeightRequest="{Binding GridHeight}" **BackgroundColor="Transparent"**>
downloaded styles from https://www.materialpalette.com/ trying to override default style, but nothing happens.
So, my question is: Which is the correct path to do that ? I really saw so many informations, about how to do that, in so many places in the code, using or xml files, or android manifest xml file, or in .cs file, or creating xml with selectors etc but no one had the expected effect.
Please, anyone could help me ?
I need a step by step teaching how to change all Android default colors, to be able to run my app at any Android versions, with the same style, especially the ListView events colors (onselect, onpressed, onfocused).
Thanks.