I have a Navigation Drawer Activity (NavActivity) in which one of the fragments (OuterFrag.xml) has a Collapsing Toolbar and a View Pager. When I scroll in the View Pager(InnerFrag.xml), the toolbar collapses, but not fully. Here's the image and the code before I go any further..
OuterFrag.xml
InnerFrag.xml
The problem has to be in OuterFrag, which contains the CollapsingToolbar. I've tried setting the height of the CollapsingToolbar to "1dp", but then a black Toolbar appears with the same size of the red are in the image above!
Found the solution!
I removed the android:fitsSystemWindows="true" from the CoordinatorLayout and the AppBarLayout and now, the Toolbar collapses completely!
If you are using CollapsingToolbarLayout inside a fragment which is inside a fullscreen activity, removing all the fitSystemWindows="true" will make it work.
Related
app:layout_collapseMode="pin"
This attribute seems to only work if the view is a toolbar and won't work on other views such as relativelayout, why?
app:layout_collapseMode= "pin"
pin is set to this mode, the Toolbar can remain on the screen when the CollapsingToolbarLayout is fully shrunk.
Fixed mode, finally fixed at the top of the fold
Because it was CollapsingToolbarLayout's attribute .
And it also used in CoordinatorLayout .
I need to display a TextView (The circular shape with "0") anchored to the toolbar, like a FAB, but it must be ALWAYS VISIBLE.
My problem is that when I collapse the toolbar (scrolling the recyclerView), at the fully collapsed state, it hides the half of the view...
The TextView layout has this properties:
app:layout_anchor="#id/appbar"
app:layout_anchorGravity="bottom|center_horizontal"
Anyone knows how to solve it?
If you want your TextView be over the toolbar, in this case, you can try to set higher elevation value to TextView. In some cases, it worked for me.
For example:
android:elevation="15dp"
I have CoordinatorLayout with AppBarLayout and Toolbar inside it:
CoordinatorLayout
- AppBarLayout
- Toolbar
animateLayoutChanges=true
Nice. And I use this code to hide/show back arrow button:
private void setBackArrowState(boolean state) {
actionBar.setDisplayHomeAsUpEnabled(state);
actionBar.setDisplayShowHomeEnabled(state);
}
There is what I got in result:
When the back arrow button hide, title not animated to it's normal position. How can I solve it?
When I scroll my RecycleView ToolBar hide or show (with animation).
How I can return ToolBar back programmatically?
If your toolbar is inside an AppBarLayout which is probably inside your CoordinatorLayout then something like this should work.
AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appBar);
appBarLayout.setExpanded(true, true);
Or to collapse it
AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appBar);
appBarLayout.setExpanded(false, true);
Here is the definition
setExpanded(boolean expanded, boolean animate)
Take note that this method is available from v23 of the support library, here is some documentation for reference, the key thing to note is "As with AppBarLayout's scrolling, this method relies on this layout being a direct child of a CoordinatorLayout."
Is that what you looking for?
Toolbar toolbar = findViewById(R.id.toolbar); // or however you need to do it for your code
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
params.setScrollFlags(0); // clear all scroll flags
link: How to enable/disable toolbar scrolling programmatically when using design support library
In order to hide the Toolbar your can just do something like this:
toolbar.animate().translationY(-toolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).start();
If you want to show it again you call:
toolbar.animate().translationY(0).setInterpolator(new DecelerateInterpolator()).start();
My problem was very similar to #Artem I tried many fix but none of them worked for me. #Jraco11's answer is correct when you use AppBarLayout. #johnrao07 not worked for me. But I found a perfect solution for this problem when we use Toolbar.
To hide Toolbar programatically
if (toolbar.getParent() instanceof AppBarLayout){
((AppBarLayout)toolbar.getParent()).setExpanded(false,true);
}
To show Toolbar programatically
if (toolbar.getParent() instanceof AppBarLayout){
((AppBarLayout)toolbar.getParent()).setExpanded(true,true);
Refer original answer(answer by #Android HHT):- programmatically-show-toolbar-after-hidden-by-scrolling-android-design-library
I'm using the new CoorindatorLayout, and the AppBarLayout is appearing over (layering over) the RecyclerView instead of having the RecyclerView anchored to the bottom of the AppBarLayout.
Your AppBarLayout must be the first child of the CoordinatorLayout for this to work!