Reputation: 224
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:
Unfortunately after landscape mode the Toolbar becomes visible again and does not hide. Check below image:
And after that I always get the following view in ActionMode even if I put the device upright:
instead of this: (desired view)
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:
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.
Upvotes: 0
Views: 213
Reputation: 224
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.
Upvotes: 0
Reputation: 1
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.
Upvotes: 0