Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore Collapsing Toolbar Layout State after screen orientation change

I've been searching for the solution of my problem for some time and didn't find solution.

I want to restore my fragment's layout after screen orientation change. I have Collapsing Toolbar Layout with banner image. After screen rotation my toolbar is always expanded, I want to restore it's behavior. How can I achieve this?

like image 961
jothaen Avatar asked Sep 14 '15 11:09

jothaen


People also ask

What is collapsing toolbar layout?

CollapsingToolbarLayout is a wrapper for Toolbar which implements a collapsing app bar. It is designed to be used as a direct child of a AppBarLayout .

How do you add a title to a collapsing toolbar?

By calling setTitleEnabled(false); , the title appeared in the toolbar. Show activity on this post. It is the same as setting title in a normal toolbar. In your xml layout file for collapsing toolbar, inside the CollapsingToolbarLayout you'll have a normal toolbar ( android.


2 Answers

You should set ID to the CoordinatorLayout. It will automatically save its state. Believe me.

See here.

like image 110
AlexMomotov Avatar answered Sep 22 '22 09:09

AlexMomotov


set id for both Coordinatorlayout and AppbarLayout.

setting id for Coordinatorlayout was not enough , after adding id to AppbarLayout it worked fine

like image 38
mhKarami Avatar answered Sep 23 '22 09:09

mhKarami