John Livermore
John Livermore

Reputation: 31313

Xamarin Android control text color through a style

For my Xamarin Android screens, I want all EditText elements to use a white font. Below is the current incarnation of my styles.xml file for my Android project. How would this be changed to ensure all text in any EditText is white?

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
        <item name="android:textColor">#ffffff</item>
    </style>

    <style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
        <item name="android:background">#333333</item>
    </style>

    <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textColor">#ffffff</item>
    </style>
</resources>

Upvotes: 0

Views: 2405

Answers (1)

York Shen
York Shen

Reputation: 9084

I want all EditText elements to use a white font.

As @Jon Douglas said, you should use editTextStyle item attribute in your MyTheme, modify your styles.xml like this:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
   <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
        ...
        <item name="editTextStyle">@style/MyEditTextStyle</item>
   </style>

   <style name="MyEditTextStyle" parent="@android:style/Widget.EditText">
       <item name="android:background">#333333</item>
       <item name="android:textColor">#ffffff</item>
   </style>

</resources>

Effect :

enter image description here

Upvotes: 1

Related Questions