0

In attributes of the main activity I set the actionbar's icon:

 [Activity(Label = "@string/app_name", Icon = "@drawable/icon1", Theme = "@style/CustomActionBarTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleInstance)]
    public class MainActivity ...

Is there any way to change this icon programatically in Xamarin Android? For example, I want to change the icon when a button is clicked.

Minimus Heximus
  • 2,683
  • 3
  • 25
  • 50
  • Does this answer your question? [How to change an application icon programmatically in Android?](https://stackoverflow.com/questions/1103027/how-to-change-an-application-icon-programmatically-in-android) – FreakyAli Nov 17 '20 at 11:23
  • @FreakyAli Well that's not Xamarin C#. – Minimus Heximus Nov 17 '20 at 12:25
  • @FreakyAli also that's about the launcher Icon. I'm asking about the icon appearing at top of the app. – Minimus Heximus Nov 17 '20 at 13:26
  • @Minimus Heximus You code just to change launcher icon not actionbar icon, so what you want to do? It is [actionbar](https://learn.microsoft.com/en-us/xamarin/android/user-interface/controls/action-bar) – Cherry Bu - MSFT Nov 18 '20 at 03:14
  • @CherryBu-MSFT I want to change action bar icon to show different states of the app. the actionbar Icon is the same as app Icon at first. But I want to change actionbar Icon sometimes. – Minimus Heximus Nov 18 '20 at 11:57
  • @CherryBu-MSFT I found the answer : `context.ActionBar.SetIcon(icon);` – Minimus Heximus Nov 24 '20 at 10:40

1 Answers1

0
var actionbar = SupportActionBar;
            actionbar.SetDisplayShowHomeEnabled(true);
            actionbar.SetLogo(Resource.Drawable.icon1);
            actionbar.SetDisplayUseLogoEnabled(true);
Jai Gupta
  • 1,374
  • 9
  • 8