Friday, March 17, 2017

Xamarin (Android) Title Bar Background Color (Popup Modal and Default Title Bar)

Setting BarBackgroundColor = Color.FromHex() will set the background color for the navigation page correctly however as soon as a page is pushed or a modal is opened that modal will not have the same color applied as above.

In order to change this popup modal color follow these steps:

1. Add Styles.xml (set as AndroidResource) in Resources\values folder in your android project.
2. Create a theme style and specify title background color. See xml below.

<?xml version="1.0" encoding="utf-8" ?>
<resources>
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>
    <style name="MyActionBar"
           parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">#003A63</item>
    </style>
</resources>

3. Set android application theme.
[Activity(Label = "My Label", Icon = "@drawable/icon", MainLauncher = true,
        Theme = "@style/CustomActionBarTheme",
        )]

No comments:

Post a Comment