Forum Xamarin.Forms

Change imageview background in toolbar.axml programatically

mac121mac121 Member ✭✭✭
edited March 2019 in Xamarin.Forms

I have set a Toolbar.axml file in the Mainactivity.cs using
ToolbarResource = Resource.Layout.Toolbar;

The Toolbar.axml is

< xmlns:android=""
                android:background="@drawable/imglogo" />

I want to change this imageview background drawable image on a click in one of my content page. Does anybody know any working solution? I tried many solutions from the internet, please assist, thanks in advance


  • jezhjezh Member, Xamarin Team Xamurai

    Have you tried MessageCenter?

  • mac121mac121 Member ✭✭✭
    edited March 2019

    @jezh, thanks for your reply! :smiley:
    Yes, I even used MessagingCenter to do the changes accordingly. My problem is which method I should use to change this imageview in toolbar set as toolbar resource.
    I basically used FindViewById for finding the toolbar using its id from layout.inflate as I can't use setContentView, because I don't use a main layout in XML. And then after getting the toolbar, I find the imageview using its ID (myToolbar.FindViewById<ImageView>) and then myImageView.SetImageResource(Resources.GetIdentifier("newimg", "drawable", this.Context.PackageName));

  • dharani1807dharani1807 Member ✭✭

    ImageView.SetImageResource() is not working for me.

    Its not updating the image via messaging center at runtime.

    Any possible fixes available already ?

Sign In or Register to comment.