Hi,
I have a project to use Theme.AppCompat.Light.NoActionBar and make side menu to slide over the default action bar and provide the android native theme for action bar. This is similar to XamarinCRM example which is available as open source.
But the similar thing when I am trying throws "Object reference not set to an instance" in MainActivity.cs in the line LoadApplication(new App());
I think you can get better idea if you role through my application. Please let me know where should I need changes / correction.
MainActivity.cs
`using System;
using Xamarin;
using Xamarin.Forms;
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using ImageCircle.Forms.Plugin.Droid;
using Xamarin.Forms.Platform.Android;
namespace SideMenuPOC.Droid
{
[Activity (Label = "SideMenu POC", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
global::Xamarin.Forms.Forms.Init (this, bundle);
FormsAppCompatActivity.ToolbarResource = Resource.Layout.toolbar;
FormsAppCompatActivity.TabLayoutResource = Resource.Layout.tabs;
ImageCircleRenderer.Init();
LoadApplication (new App ());
}
}
}
`
AndroidManifest.xml
<?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.sidemenupoc">
<uses-sdk android:minSdkVersion="15" />
<application android:label="SideMenuPOC" android:icon="@drawable/icon" android:theme="@style/SideMenuPOC">
</application>
</manifest>
App.cs
<?xml version="1.0" encoding="UTF-8"?>
<Application
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="SideMenuPOC.App">
</Application>
App.xaml.cs
`using System;
using System.Collections.Generic;
using Xamarin.Forms;
using SideMenuPOC.Pages;
namespace SideMenuPOC
{
public partial class App : Application
{
static Application app;
public static Application CurrentApp
{
get { return app; }
}
public App ()
{
InitializeComponent ();
app = this;
var temp = false;
if (temp)
{
//MainPage = new SplashPage();
}
else
{
GoToRoot();
};
}
public static void GoToRoot()
{
if (Device.OS == TargetPlatform.iOS)
{
CurrentApp.MainPage = new RootPage();
}
else
{
CurrentApp.MainPage = new RootPage();
}
}
}
}
`
Resources/values-v21/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="SideMenuPOC" parent="SideMenuPOC.Base">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>
Resources/values/styles.xml
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="SideMenuPOC" parent="SideMenuPOC.Base">
</style>
<style name="SideMenuPOC.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:windowBackground">@color/window_background</item>
</style>
</resources>
Resources/values/colors.xml
`<?xml version="1.0" encoding="utf-8"?>
#53ba9d
#42947d
#8de2d5
#F5F5F5
`
Resources/layout/toolbar.axml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />
Resources/layout/tabs.axml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabIndicatorColor="?attr/colorAccent"
app:tabGravity="fill"
app:tabMode="fixed" />
It would be great if any one could explain.
Thanks,
Bhuvanesh