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

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


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

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
VisualStudio.15.Release/15.2.0+26430.12
Microsoft .NET Framework
Version 4.7.02046

Installed Version: Enterprise

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

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

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

Note You need to log in before you can comment on or make changes to this bug.