Bug 38227 - Can't use style.xml anymore - No custom theming
Summary: Can't use style.xml anymore - No custom theming
Status: RESOLVED INVALID
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.0.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-01-31 05:54 UTC by adrianknight89
Modified: 2016-03-11 22:02 UTC (History)
5 users (show)

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


Attachments
style.xml can't be used (46.02 KB, application/zip)
2016-01-31 05:54 UTC, adrianknight89
Details


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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description adrianknight89 2016-01-31 05:54:52 UTC
Created attachment 14816 [details]
style.xml can't be used

<package id="Xamarin.Forms" version="2.1.0.6508-pre3" targetFramework="monoandroid60" />

Compile using Android version: Use Latest Platform (Android 6.0 Marshmallow)
Minimum Android to target; Android 4.0.3 (API Level 15)
Target Android version: Use Compile using SDK version

Compiling this on VS2015 / Win10
Xamarin 4.0.1.89 (413372c)
Xamarin.Android 6.0.1.10 (e98e962)

Application errors out on launch at LoadApplication(new App()); in MainActivity.cs with the following error:

01-31 07:07:08.315 I/MonoDroid(26231): UNHANDLED EXCEPTION:
01-31 07:07:08.315 I/MonoDroid(26231): System.NullReferenceException: Object reference not set to an instance of an object
01-31 07:07:08.315 I/MonoDroid(26231):   at Xamarin.Forms.Platform.Android.Platform.UpdateActionBarHomeAsUp (Android.App.ActionBar actionBar) [0x0001d] in <filename unknown>:0 
01-31 07:07:08.315 I/MonoDroid(26231):   at Xamarin.Forms.Platform.Android.Platform.HideActionBar () [0x0000d] in <filename unknown>:0 
01-31 07:07:08.315 I/MonoDroid(26231):   at Xamarin.Forms.Platform.Android.Platform.UpdateActionBar () [0x000a0] in <filename unknown>:0 
01-31 07:07:08.315 I/MonoDroid(26231):   at Xamarin.Forms.Platform.Android.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x000bd] in <filename unknown>:0 
01-31 07:07:08.315 I/MonoDroid(26231):   at Xamarin.Forms.Platform.Android.FormsApplicationActivity.InternalSetPage (Xamarin.Forms.Page page) [0x000b7] in <filename unknown>:0 
01-31 07:07:08.315 I/MonoDroid(26231):   at Xamarin.Forms.Platform.Android.FormsApplicationActivity.SetMainPage () [0x0000c] in <filename unknown>:0 
01-31 07:07:08.315 I/MonoDroid(26231):   at Xamarin.Forms.Platform.Android.FormsApplicationActivity.LoadApplication (Xamarin.Forms.Application application) [0x0002d] in <filename unknown>:0 
01-31 07:07:08.325 I/MonoDroid(26231):   at App23.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00020] in C:\Users\xyz\Documents\Visual Studio 2015\Projects\App23\App23\App23.Droid\MainActivity.cs:24 
01-31 07:07:08.325 I/MonoDroid(26231):   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00011] in /Users/builder/data/lanes/2692/e98e9627/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.App.Activity.cs:2857 
01-31 07:07:08.325 I/MonoDroid(26231):   at (wrapper dynamic-method) System.Object:0d4ea3af-d627-4c79-af83-fd09d236a7f1 (intptr,intptr,intptr)
01-31 07:07:08.335 W/art     (26231): JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable

I noticed Xamarin.Android works fine, so this must be a Forms issue.

Please see repro.

Also created a thread: http://forums.xamarin.com/discussion/60091/updating-xamarin-to-the-latest-stable-seems-to-have-broken-android-custom-styles-for-xf#latest
Comment 1 adrianknight89 2016-01-31 06:11:43 UTC
This issue is happening on both Visual Studio and Xamarin Studio.
Comment 2 adrianknight89 2016-02-02 00:53:21 UTC
I rolled back to the following versions, however the issue still persists:

Xamarin 4.0.0.1717
Xamarin.Android 6.0.0.35
Comment 3 Jonathan Pryor 2016-02-02 10:55:40 UTC
Based on the stack trace, I'm going to surmise that the exception happens because Activity.ActionBar is null.

Based on that assumption, observe $ANDROID_SDK_PATH/platforms/android-23/data/res/values/themes.xml:

    <resources>
      <style name="Theme">
        <!-- ... -->
        <item name="windowActionBar">false</item>
      </style>
      <!-- ... -->

      <!-- Default theme with an Action Bar. -->
      <style name="Theme.WithActionBar">
        <item name="windowActionBar">true</item>
      </style>

i.e. the default android:Theme resource does NOT support the ActionBar, and thus (I assume) Activity.ActionBar returns null.

If you need the action bar -- and presumably Xamarin.Forms requires the action bar -- then use a style which supports it:

    <style name="MyTheme" parent="android:Theme.WithActionBar">

Please try that.
Comment 4 adrianknight89 2016-02-02 15:14:16 UTC
Jonathan, I do not need the action bar or the status bar. I want to go full screen. If, however, Xamarin Forms requires an ActionBar, then I can use another theme and hide it programmatically at startup. I'll try your suggestion later today and get back with you. I remember android:Theme working for me before I upgraded Xamarin. I just can't remember what version of Xamarin I was using before.
Comment 5 adrianknight89 2016-02-02 18:41:40 UTC
Theme.WithActionBar did not work for me. I think the problem is using any theme throws an error. Did you test run the repro I submitted? Did it work for you? Please suggest a reason as to why this bug's status was changed to "NEEDINFO".
Comment 6 adrianknight89 2016-02-03 14:50:02 UTC
Please suggest a reason as to why this bug's status was changed to "NEEDINFO". I'd like to understand if my repro is producible on your end.
Comment 7 adrianknight89 2016-02-14 04:26:39 UTC
I noticed the problem is with these two lines:

<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>

These are throwing the exception whether I set my theme to android:Theme or android:Theme.WithActionBar. They used to work before.
Comment 8 adrianknight89 2016-03-11 22:02:17 UTC
This could be closed as I figured out a way to hide the title bar properly. I believe I was approaching things from the wrong perspective.