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

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

Related

ViewPager with TabLayout inside a NavHostFragment in an AppBarLayout

Ok, please bear with me: I'm using the android navigation component for a new app I'm building. I need the ActionBar and the BottomNavigationView to hide on scroll, which I've done successfully by using an AppBarLayout inside a CoordinatorLayout.
In my app's theme I'm using "windowActionBarOverlay = true", since I need the ActionBar to be transparent in some of my fragments. In one of my Fragments, I have a ViewPager with a TabLayout, and a solid ActionBar. To overcome the issue that windowActionBarOverlay creates, I've added some paddingTop to my whole fragment.
However, this creates a problem when the user scrolls, since the ActionBar gets hidden away, and there is an empty space where the padding is.
I can use two solutions, although I don't know how to implement each of them:
Make the ViewPager scroll with the ActionBar. How can I do that, in my situation, where the ViewPager is inside a Fragment in a NavHostFragment?
Make the ActionBar not hide itself when the user scrolls. Is there a way to disable this programatically for particular fragments?
If anyone knows how to implement one of the two solutions, please let me know.

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?

Using Toolbar in Fragment or in Activity

I am using Android-ObservableScrollView library. Everything works great, but I have activity for holding fragments, so all views are encapsulated in the fragment. In activity there is only FrameLayout for holding fragments.
So I need to use Toolbar in my application, I have several ideas how to implement this.
Use Toolbar in activity, in this case my layout will have FrameLayout and Toolbar. In this way I have communicate with activity whenever I need to do something with toolbar, I can also obtain it by using getSupportedActionBar() from fragment.
Use Toolbar inside fragment (in its layout) setting in each fragment view creation. And each time I change fragment I have to add new Toolbar to the activity. In some fragment I am going to have different toolbars but not in all. Is it good approach to store Toolbar inside fragment.
The problem that I can see in using second approach, if there will be more than one fragment on the screen there will be also several toolbars.
Please suggest what will be the right way in this case.
Thank you.
You should use first method.
While using first method will have less problem then second one because in second method you have to define toolbar for many times which is not good programming.

Hide ToolBar on Fragment Scroll

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

ViewPager inside Fragment android

I am using Fragment for Slider menu in Android. Source : Android Slider Menu
Now, I want to add ViewPager inside first Fragment which is Home. So I found some tutorials for it. But all are using FragmentActivity so I am not able to call it inside Fragment.
Please help me regarding this.
I think this should help you out.The key is to use Nested Fragment calls instead of a calling an Activity that uses the FragmentActivity.Find more about Nested Fragment calls here Please check out this question and see how this is implemented.
Android: Viewpager inside a fragment of Navigation Drawer

Categories

Resources