locked
Change imageview background in toolbar.axml programatically RRS feed

  • Question

  • User380835 posted

    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

    Thursday, March 7, 2019 9:13 AM

All replies

  • User371688 posted

    Have you tried MessageCenter?

    Friday, March 8, 2019 9:27 AM
  • User380835 posted

    @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));

    Friday, March 8, 2019 10:02 AM
  • User382186 posted

    ImageView.SetImageResource() is not working for me.

    Its not updating the image via messaging center at runtime.

    Any possible fixes available already ?

    Tuesday, March 12, 2019 10:36 AM