2

I have an Android app that uses Xamarin Forms 2.0. I made a custom theme to set some colors. I created these files:

Resources/values/styles.xml (AndroidResource)

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="SmartbitLight" parent="SmartbitLight.Base">

  </style>

  <style name="SmartbitLight.Base" parent="Theme.AppCompat.NoActionBar">
    <item name="colorPrimary">@color/blueLight</item>
    <item name="colorPrimaryDark">@color/blueDark</item>
    <item name="colorAccent">@color/grey</item>
    <item name="android:windowBackground">@color/white</item>
    <item name="android:textColorPrimary">@color/white</item>
    <item name="android:statusBarColor">@color/blue</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
  </style>
</resources>

Resources/values-v21/styles.xml (AndroidResource)

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="SmartbitLight" parent="SmartbitLight.Base">

  </style>
</resources>

Resources/values/colors.xml (AndroidResource)

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <color name="blueLight">#3cc1f1</color>
  <color name="blue">#33a4cd</color>
  <color name="blueDark">#33a4cd</color>
  <color name="grey">#7d7d7d</color>
  <color name="white">#ffffff</color>
</resources>

And then I have a MainActivity where I hook up this theme to the app:

[Activity(
    Label = "Smartbit", 
    Icon = "@drawable/icon", 
    MainLauncher = true, 
    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
    Theme = "@style/SmartbitLight")]
public class MainActivity : FormsAppCompatActivity

This doesn't work correctly though: the app bar is white instead of the intended blue, and the 'android:windowBackground' turns the text and border of my Entry control white as well.

Leon Cullens
  • 12,276
  • 10
  • 51
  • 85

2 Answers2

0

Try adding the name of your theme (SmartbitLight) in the manifest, as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.test">
    <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="23" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:label="test" android:theme="@style/SmartbitLight"></application>
</manifest>

path: your_app / Droid / Properties / AndroidManifest.xml

Jonathan Zúñiga
  • 645
  • 3
  • 13
  • 25
  • Actually the theme is working now, it's just that not all colors or shown (most notably the toolbar which is white instead of blue). Your code snippet is just another way to set the theme (which I did by setting [Activity(Theme = "@style/SmartbitLight")] – Leon Cullens Mar 04 '16 at 01:50
  • @LeonCullens hi! oh, i see... but your file styles.xaml, don't need to be renamed with the extension xml? :/ You can found complete info. here: http://motzcod.es/post/115523285992/material-design-theming-for-xamarinforms-android and here: https://developer.xamarin.com/guides/android/user_interface/material_theme/ Also, make sure you have >= v21 set as your compile target. – Jonathan Zúñiga Mar 04 '16 at 16:54
  • @Johathan absolutely right, it's named .xml but I made a typo :) I actually found the solution, I'll add my answer. – Leon Cullens Mar 05 '16 at 12:10
0

I managed to get the custom theme working with all the colors for the appbar and everything. I created a toolbar.axml file and registered it in my FormsAppCompatActivity as described here: https://blog.xamarin.com/material-design-for-your-xamarin-forms-android-apps/.

Leon Cullens
  • 12,276
  • 10
  • 51
  • 85