CustomView in ActionBar disappear when orientation change ? (AppCompat)

297 Views Asked by At

Problem :

I personalized my actionBar (SupportActionBar) with a renderer on my CustomNavigationPage beacause I use AppCompat theme. So, I added my CustomView (a SearchBar) in the actionbar from this class.

But ... when we change the orientation (Portrait->Landscape / Landscape->Portrait) my view disappear and I must recreate my CustomNavigationPage if I want to see again my CustomView.

I need your help, thank you in advance !

1

There are 1 best solutions below

0
On

Finally, I solved this problem by the id of the toolbar :

        int toolbarId = Resources.GetIdentifier("toolbar", "id", Android.App.Application.Context.PackageName);
        Android.Support.V7.Widget.Toolbar actionBar = (Android.Support.V7.Widget.Toolbar)FindViewById(toolbarId);

When we use AppCompat, it's the toolbar which is used. Then, I remove views and add again my CustomView.