Forum Xamarin.Android

Update Image in Toolbar when rotation

WikkedWikked DEMember
edited December 2017 in Xamarin.Android

I'm currently encounter a problem with the Toolbar with Xamarin Android. I have only the MainActivity (since it is a Xamarin Forms project) where I set the Toolbar with
ToolbarResource = Resource.Layout.CustomToolbar;

CustomToolbar is a axml file

< xmlns:android="" android:id="@+id/customToolbar" android:layout_width="match_parent" android:layout_height="match_parent" android:minHeight="?android:attr/actionBarSize" android:background="?android:attr/colorPrimary" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<ImageView android:id="@+id/toolbarImage" android:layout_width="100dp" android:layout_height="match_parent" android:layout_gravity="right" android:layout_weight="1" android:paddingRight="5dp"/> </>

The Image Source in the ImageView is set in the OnStart Method of the MainActivity. The image is received from the server as base64 string.

ImageView toolbarImg = this.FindViewById<ImageView>(Resource.Id.toolbarImage);
byte[] imageBytes = Convert.FromBase64String(imgAsBase64);
Android.Graphics.Bitmap decodedByte = Android.Graphics.BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);

So far it is working, when I'm starting the app I can see the image in the toolbar perfectly. But as soon as I change the orientation of the device the image disappears.
For the Android Activity I have set the configuration changes to Orientation and ScreenSize. So what I've tried was to set the image in OnConfigurationChanged method, same as descriped above. This didn't solved my problem. I've also tried using methods like Invalidate(), PostInvalidate, RequestLayout and also tried to set the ImageView in a Linear/Relativelayout.

I've also found on StackOverflow that at someone had a quite similiar problem where changing the ViewState of the ImageView to Gone and after setting the image again to Visible, but none of my approaches solved it.

I acutally don't know what I'm doing wrong or could try out, so I'm hoping on some help here.
Thanks in advance

EDIT: needed to remove the link from xmlns:android="" otherwise I couldn't post this question. It is set to the right schema there.


  • WikkedWikked DEMember

    Problem still exists and didn't find any solution. Does someone has an idea?

Sign In or Register to comment.