Wikked
Wikked

Reputation: 107

Different app icon for each configuration

For my app I want to have two different versions (live and dev). The version will be build with a different build configuration.

What I want to achieve is to have a different app icon shown on the device depending on which version/build configuration I used. I already have searched for solutions but only found some which advices to use different Manifests/csproj but I can't go with this approach.

So is there any other way to have different icons depending on the configuration?

Upvotes: 2

Views: 337

Answers (1)

Alexrgs
Alexrgs

Reputation: 941

Your best bet is to remove the icon config from the manifest and add it to your MainActivity.

It will look like this:

using Android.App;
using Android.Content.PM;
using Android.OS;
using Microsoft.Practices.Unity;
using Prism.Unity;

namespace BlankApp2.Droid
{

#if DEBUG
    [Activity(Label = "Debug BlankApp2", Icon = "@drawable/debugIcon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
#else
    [Activity(Label = "Prod BlankApp2", Icon = "@drawable/prodIcon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
#endif
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App(new AndroidInitializer()));
        }
    }

    public class AndroidInitializer : IPlatformInitializer
    {
        public void RegisterTypes(IUnityContainer container)
        {
            // Register any platform specific implementations
        }
    }
}

Upvotes: 1

Related Questions