Bug 43723 - Default styles on custom views are ignored
Summary: Default styles on custom views are ignored
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 7.3 (15.2)
Hardware: PC Mac OS
: Normal normal
Target Milestone: master
Assignee: Jonathan Pryor
Depends on:
Reported: 2016-08-24 21:43 UTC by Justin
Modified: 2017-06-27 20:14 UTC (History)
4 users (show)

Tags: XATriaged, ac
Is this bug a regression?: ---
Last known good build:

Side-by-side showing Xamarin (on left) and native Android (on right) (79.56 KB, image/png)
2016-08-24 21:43 UTC, Justin
Xamarin Studio Solution (1.36 MB, application/zip)
2016-08-24 21:44 UTC, Justin
Android Studio Solution (419.09 KB, application/x-zip-compressed)
2016-08-24 21:47 UTC, Justin

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 43723 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Justin 2016-08-24 21:43:23 UTC
Created attachment 17201 [details]
Side-by-side showing Xamarin (on left) and native Android (on right)

When creating a custom view in Android, you are able to specify a default style for it.  To do this, the following steps must be taken:

1) Create an attribute with format="reference" in Attrs.xml (see my_test_style in sample projects)
2) Create a style with the attributes desired for the default style in Styles.xml (see MyCustomStyle in sample projects)
3) In Themes.xml set the value of the attribute created in step 1 to the style created in step 2 (see sample projects)
4) Make sure the theme is used by your app in the manifest file
5) Create a custom View or ViewGroup class (see CustomFrameLayout class in sample projects)
6) Set up the constructors to use the attribute defined in step 1.
7) Use your custom view in a layout file (see Main.axml in xamarin project and Activity_Main.xml in native project)
8) DO NOT set a style on your custom view... the values in the style you created should get set by default.
9) Launch your app... Styles are set properly in native Android but completely ignored in Xamarin
Comment 1 Justin 2016-08-24 21:44:58 UTC
Created attachment 17202 [details]
Xamarin Studio Solution
Comment 2 Justin 2016-08-24 21:47:40 UTC
Created attachment 17203 [details]
Android Studio Solution
Comment 3 Justin 2016-08-24 21:49:44 UTC
Comment on attachment 17201 [details]
Side-by-side showing Xamarin (on left) and native Android (on right)

Ignore the action bar... that is a difference in how XS and AS set up default projects.
Also, ignore the text in the Android screenshot. It has a typo... That should say "blue background" instead of red.
Comment 4 John Miller [MSFT] 2017-06-27 20:14:55 UTC
I was able to reproduce the issue with the sample project and directions given. 

Microsoft Visual Studio Enterprise 2017 
Version 15.2 (26430.12) Release
Microsoft .NET Framework
Version 4.7.02046

Installed Version: Enterprise

Xamarin (1be4f0c)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK (9dbc4c5)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK (4cffddf)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.