locked
Remove icon from action bar from xamarin forms android project RRS feed

  • Question

  • User62010 posted

    Hi, Can someone help me in removing icon from action bar ?

    Thanks, Ashish jha

    Monday, March 9, 2015 10:16 AM

All replies

  • User73569 posted

    Yep. I did this by creating a custom NavigationRenderer. I tried to do it without a renderer but I gave up in the end.

    Here's the renderer: ``` public class RootNavigationRenderer : NavigationRenderer { protected override void OnElementChanged(ElementChangedEventArgs e) { base.OnElementChanged (e);

            RemoveAppIconFromActionBar ();
        }
    
        void RemoveAppIconFromActionBar()
        {
            // http://stackoverflow.com/questions/14606294/remove-icon-logo-from-action-bar-on-android
            var actionBar = ((Activity)Context).ActionBar;
            actionBar.SetIcon (Resource.Color.transparent);
        }
    }
    

    ```

    If anyone managed to do it without a renderer, I'd love to know...

    Monday, March 9, 2015 1:36 PM
  • User109849 posted

    Hello Prakash & Peter,

    I just solved this issue by modifying activity tag in MainActivity.cs. It actually converts into android manifest file.

    Code:
    [Activity (Label = "Todo.Android.Android", MainLauncher = true, Icon="@android:color/transparent")]

    => Icon="@android:color/transparent". This does the trick. No Icon on the Action bar.

    I am using Shared Project.

    Regards, Kamran

    Saturday, March 14, 2015 8:00 PM
  • User97927 posted

    @Kamran.8611 But then you have also no app icon right? When I set it in portable App, the app icon is also transparent

    Thursday, March 19, 2015 2:21 PM
  • User102046 posted

    @FokkeVermeulen Well i added a 10X10 transparent image to resources. Changed navigation bar icon in PCL by calling NavigationPage.SetTitleIcon("DummyIcon")

    Thursday, March 19, 2015 3:20 PM
  • User97927 posted

    @Xami3 thanks or the idea. I will use a 1x1 transparent image. I also tested it with the renderer thing. It worked too, but everything without renderer sounds good ;)

    Friday, March 20, 2015 8:32 AM
  • User102046 posted

    @FokkeVermeulen yeah i am allergic to renderer as well :smiley:

    Friday, March 20, 2015 9:34 AM
  • User94701 posted

    @PeterMajor Hi sorry for basic question but how do you implement a custom NavigationRenderer

    Friday, March 27, 2015 10:01 AM
  • User73569 posted

    @Craig.4350

    Hi Craig,

    Easy as adding this to your Android project!

    ``` using Android.App; using Android.Graphics.Drawables; using Example; using Xamarin.Forms; using Xamarin.Forms.Platform.Android;

    [assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomNavigationRenderer))]

    namespace Example { public class CustomNavigationRenderer : NavigationRenderer { protected override void OnElementChanged(ElementChangedEventArgs e) { base.OnElementChanged (e);

            RemoveAppIconFromActionBar ();
        }
    
        void RemoveAppIconFromActionBar()
        {
            // http://stackoverflow.com/questions/14606294/remove-icon-logo-from-action-bar-on-android
            var actionBar = ((Activity)Context).ActionBar;
            actionBar.SetIcon (new ColorDrawable(Color.Transparent.ToAndroid()));
        }
    }
    

    } ```

    Friday, March 27, 2015 5:06 PM
  • User73569 posted

    @Xami3 - If you're doing any non-trival Xamarin Forms app, you'll be using renderers.

    Learn to love them and they'll love you back!

    Friday, March 27, 2015 5:08 PM
  • User94701 posted

    Thanks @PeterMajor

    Friday, April 17, 2015 4:10 PM
  • User105175 posted

    "trivial" lol. sorry, but I'll take the simple, functional solution, peter.

    Thursday, June 25, 2015 3:47 PM
  • User134893 posted

    @PeterMajor is there any way to edit the background color within that custom renderer?

    Monday, August 24, 2015 5:18 PM
  • User132979 posted

    How to change Search Bar Icon image. ?

    Friday, October 16, 2015 11:04 AM
  • User155499 posted

    In your MainActivity.cs add this:

    this.ActionBar.SetIcon(Android.Resource.Color.Transparent);

    Friday, November 20, 2015 7:31 AM
  • User185802 posted

    @Carlos Forero, thank you for your comment it is working for me.

    Monday, January 25, 2016 8:45 AM
  • User185802 posted

    @Carlos Forero, could you please tell me how can i title will be set in center in toolbar.

    Monday, January 25, 2016 9:01 AM
  • User188797 posted

    actionBar.SetIcon (Resource.Color.transparent);> @PeterMajor.5288 said:

    Yep. I did this by creating a custom NavigationRenderer. I tried to do it without a renderer but I gave up in the end.

    Here's the renderer: ``` public class RootNavigationRenderer : NavigationRenderer { protected override void OnElementChanged(ElementChangedEventArgs e) { base.OnElementChanged (e);

          RemoveAppIconFromActionBar ();
      }
    
      void RemoveAppIconFromActionBar()
      {
          // http://stackoverflow.com/questions/14606294/remove-icon-logo-from-action-bar-on-android
          var actionBar = ((Activity)Context).ActionBar;
          actionBar.SetIcon (Resource.Color.transparent);
      }
    

    } ```

    If anyone managed to do it without a renderer, I'd love to know...

    This worked, one small change for me: actionBar.SetIcon (null);

    It was risky as I didn't know if null would cause an exception here - tried it and it worked a charm, for my purposes the app icon is a complete waste of space in the navigation bar. It is now gone and full titles can be shown in the spot.

    Wednesday, January 27, 2016 11:47 PM
  • User148945 posted

    @Carlos Thanks! Worked for me!

    Tuesday, February 2, 2016 2:30 PM
  • User841 posted

    In case anyone is trying to do this in Material design:

        /// <summary>
        /// The intent of this custom renderer is to hide the logo on the nav bar for modal windows
        /// </summary>
        public class CustomNavigationRenderer : Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer
        {
            private static ColorDrawable TransColor = new ColorDrawable(Color.Transparent.ToAndroid());
    
            protected override void OnElementChanged(ElementChangedEventArgs<NavigationPage> e)
            {
                base.OnElementChanged(e);
    
                RemoveAppIconFromActionBar();
            }
    
            void RemoveAppIconFromActionBar()
            {
                var toolbar = this.FindViewById(Resource.Id.toolbar);
                if (toolbar != null)
                {
                    var tb = toolbar as Toolbar;
                    if (tb != null)
                    {
                        tb.Logo = TransColor;
                    }
                }
            }
        }
    
    Wednesday, February 3, 2016 7:27 PM
  • User44771 posted

    We can directly access the ActionBar Icon and set it to transparent in the Android Project. That will be the simpler and direct method. This is how I do it.

    protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); global::Xamarin.Forms.Forms.Init (this, bundle); LoadApplication (new App ()); ActionBar.SetIcon (new ColorDrawable (Android.Graphics.Color.Transparent));; }

    Monday, February 15, 2016 5:22 AM
  • User223731 posted

    @CarlosForero said: In your MainActivity.cs add this:

    this.ActionBar.SetIcon(Android.Resource.Color.Transparent);

    Hi @CarlosForero I didn't fint the method SetIcon in the ActionBar context

    Monday, May 9, 2016 11:53 AM
  • User205049 posted

    NO,we need noactionbar!!

    Friday, May 27, 2016 4:18 PM
  • User226569 posted

    @CarlosForero This worked perfectly. Thank you.

    Saturday, June 11, 2016 11:05 PM
  • User223656 posted

    here it is the very easy solution go to the MainActivity.cs Class before LoadApplication(new App()); add this code ActionBar.SetIcon(null);

    It worked for me.

    Wednesday, July 13, 2016 6:40 PM
  • User238772 posted

    @CarlosForero This worked perfectly. Thank you.

    Wednesday, July 27, 2016 2:41 AM
  • User100407 posted

    @CarlosForero Thanks

    Wednesday, August 3, 2016 6:03 AM
  • User253410 posted

    Thanks @mubi

    Wednesday, August 31, 2016 1:45 PM
  • User267631 posted

    Thanks @mubi

    Tuesday, October 25, 2016 11:18 AM
  • User126285 posted

    Thanks @mubi

    Monday, March 6, 2017 6:23 PM
  • User326262 posted

    @CarlosForero Thanks

    Monday, May 29, 2017 10:30 AM
  • User72380 posted

    [Activity(Label = "MyApp.Droid", //Icon = "@drawable/icon", Icon = "@android:color/transparent", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, Theme = "@android:style/Theme.Holo.Light")] public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity

    This has worked for me. Thank you!

    [edit]

    buuut, for some reason, the application icon has gone too. :(

    now I've tried as said by @mubi :

        ActionBar.SetIcon(null); 
    
            LoadApplication(new App());
        }
    

    aaaand, works greatful.

    app has icon and actionbar hasnot.

    thank you very much!

    Tuesday, August 8, 2017 3:44 PM
  • User173352 posted

    Thanks @mubi

    Tuesday, December 19, 2017 9:33 PM