Change imageview background in toolbar.axml programatically

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

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

The Toolbar.axml is

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/toolbar"...>
            <ImageView
                android:id="@+id/logo"
                android:layout_gravity="center"
                android:background="@drawable/imglogo" />
 </android.support.v7.widget.Toolbar>

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

Answers

  • jezhjezh Xamurai Member, Xamarin Team Xamurai

    Have you tried MessageCenter?

  • mac121mac121 ✭✭✭ Member ✭✭✭
    edited March 8

    @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.