Android - ActionMode after landscape the Toolbar becomes visible and does not hide

195 Views Asked by At

I have a root view and this root view contains a fragment with viewpager. This is my ContentFragment. And I update view of this ContentFragment for viewpager behaviour. Now, when I activated ActionMode for a view of ContentFragment, the ActionMode initially hides the Toolbar of root view which is desired result like below:

enter image description here

Unfortunately after landscape mode the Toolbar becomes visible again and does not hide. Check below image:

enter image description here

And after that I always get the following view in ActionMode even if I put the device upright:

enter image description here

instead of this: (desired view)

enter image description here

When I manually hide Toolbar by using this line of code:

toolbar.visibility = View.INVISIBLE

or

toolbar.visibility = View.GONE

inside root view, then the ActionMode overlaps first item of ListView like below:

enter image description here

I have

<item name="windowActionModeOverlay">true</item>

used in themes.xml and I'm sure. But the question is why does ActionMode initially hide the Toolbar, but after landscape mode the Toolbar becomes visible again and never hides.

2

There are 2 best solutions below

0
On BEST ANSWER

Fixing actionBarSize to the toolbar height resolved my issue. I just added

<item name="actionBarSize">@dimen/toolbar_action_mode_height</item>

to my themes. And issue resolved.

2
On

I think this might be caused by the recreation of the fragment. The fragment creates the action bar but when the device is rotated the fragment is recreated but the action bar is not updated on the fragments recreated state hence the toolbar is shown again

You might want to do something like this in on create fragment

//Write in OncreatFragment
If (getActivity().getSupportActionBar() != null ) {
//hide action bar
//Toolbar should automatically be shown as you said
} else {
//Do nothing since this is the start of the fragment.
}

Additionally you should save a boolean or int so that whenever the fragment is recreated while the action bar was shown you would re-create the action bar

//Write in OncreatFragment
If (getActivity().getSupportActionBar() != null ) {
   if (wasActionBarPreviouslyShown) {
   //Receate the action bar this should automatically hide the toolbar
   } else {
   //hide the action bar since it wasn't previously shown toolbar should automatically be shown as you have stated.               }
} else {
    //Do nothing.
}

I hope this helps even if just a little.