Hide ToolBar on Fragment Scroll - android

so my ToolBar is in my MainActivity layout, along with a container underneath it for the fragments. All fragments have a ScrollView, I would like to hide the ToolBar when a Fragments scrollview is scrolled. What is the best way around having the fragment and main activity communicate?

To communicate between activity and Fragment, implementing an interface is the best option i know. Read more about it here http://developer.android.com/training/basics/fragments/communicating.html

Related

Scroll Activity Toolbar off screen scrolling Recyclerview in fragment

I have an activity that hosts 2 fragments, I am currently using a coordinator layout in both fragments with appbarlayout and toolbar layout, I have set it up this way to scroll the toolbar off screen with my recyclerview. This has been causing my layout issues as I've posted here So I am looking to change my approach. If I can the activity will host the tool bar/app bar layout in a coordinator layout.
The problem with this approach is that the 2 fragments have recyclerviews with views at the bottom (buttons). So I'm wondering if it's possible to transfer the scroll from the fragment recyclerview by setting the appbehaviour while maintaining the position of the buttons on the bottom?
Any help on this would be appreciated as I've spent days trying to figure out the alternative approach linked above.
Thanks
Yes it's possible, I'm doing this in an activity with a ViewPager, you just need to add
app:layout_behavior="#string/appbar_scrolling_view_behavior"
in the layout that holds the fragments (in my case the viewpager)

Can we use CoordinatorLayout and TabLayout in Fragment?

I am using this Siliding menu https://android-arsenal.com/details/1/1398
On Home Page it load Fragment.
And i Want to design Home screen as http://blog.nkdroidsolutions.com/collapsing-toolbar-with-tabs-android-example/.
So, my question is
can we use coordinator layout and TabLayout(Which will have again three fragment) in Fragment?
if not what is other solution?

Swap toolbar on fragment launch

I have an activity with a NavigationDrawer and a full screen fragment. Clicking on various items in the NavigationDrawer inflates a different fragment in the activity.
I would like to also swap in a different toolbar when launching a different fragment. The reason I want to do that instead of inflating a new menu is that the toolbar I want to swap in is a bit complicated and has things like an EditText in it.
Is there some way to do this either in the activity before inflating a fragment or maybe in the fragment?
Just include your Fragment specific toolbar in your Fragment's layout so that it's visible in your Fragment permanently.
Now in the onStart() method of your Fragment -
getActivity().getSupportActionBar().hide();
This will hide the activity's default toolbar so that it does not overlap with the Fragment's toolbar.
Then again in the onStop() method of your Fragment -
getActivity().getSupportActionBar().show();
So that the Activity's toolbar is visible again outside that Fragment.
each time you call a fragment use "invalidateOptionsMenu" and using fragment id you can set visibility of menuitems in toolbar... if that is what u need... hope it helps

How to implement collapsing Toolbar with fragments and NavigationDrawer?

I have an application with Activity, Fragment inside activity, Toolbar and Navigation Drawer.
I need a Toolbar will hiding when I scroll content of fragment.
Following manual I need to put ToolBar and scrollable content inside same XML file. But my scrollable content placed in Fragment and ToolBar placed in Activity. How to implement collapsing Toolbar?
You need to use CoordinatorLayout
Try to use this guide. There's good explanation

How to hide the toolbar in a ViewPager when using Scrolling RecyclerView?

I've got a toolbar in a view-pager (tabbed toolbar with horizontal swipe navigation) and each tab has its own fragment with a recyler_view. I now want to hide the toolbar when my recyler_view scrolls. In my fragment i added the on scroll-listener and want to call there a method in its activity class to hide the toolbar. The toolbar is created in the activity. How can I call this method from my fragment? or would it be better to implement this hiding method in my fragment itself. But then how can i "contact" my toolbar, that is created in the activity and not in the fragment. I have found solutions, but none of them talks about a recylcer_view in a fragment and view-pager for tabbed navigation.
Would be great if you can help me...
I just had the same problem as you and solved it by using a library ObservableScrollView.
Have a look at ViewPagerTabRecyclerViewFragment.
If you don't want to use a library you still can have a look at how they implemented it as the lib is Open Source

Categories

Resources