ViewPager with TabLayout inside a NavHostFragment in an AppBarLayout - android

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.

Related

Jetpack BottomNavigationView How to remove content fade in animation

I'm creating a single activity applicatition. Inside Activity there is a BottomNavigationView
with NavHostFragment. Bottom navigation view comprise of multiple menu items.
For easy to explain lets say there are three fragments "FragmentOne", "FragmentTwo", "FragmentThree"
each fragment have a different Toolbar. As a example "FragmentOne" is haveing a Toolbar with CollapingToolbarLayout, and "FragmentTwo" has a Normal Toolbar Design and "FragmentThree" has a toolbar with Image.
I have included different design Toolbars in each fragment and the BottomNavigationView is inside Activity.
Where select each bottom navigation menu, fragments are navigating correctly but content is showing fade in animation/transition.
I have set the app theme as Theme.AppCompat.Light.NoActionBar So now since Toolbar is also inside the fragment content area Toolbar also showing fade in transition.I'm okay with content transition but Toolbar should stay Solid.
Kindly help to me to solve this and feel free to request more information.

Android - Make StatusBar transparent on a specific fragment in ViewPager

I have a ViewPager with several fragments, his layout includes only the ViewPager with a TabLayout, nothing else.
And one specific fragment (in view pager) which has a coordinator layout with collapsing toolbar (on the right)
What I want to do is to set the StatusBar transparent only on the right fragment. Just imagine I want to move the picture on the right fragment completely top
I've tried several methods like android:fitsSystemWindows="true" , make the ViewPager fullscreen (it wasn't what I expected) or modify application theme. But this is a specific situation that I can't find any solution. Thanks for any ideas.

Nested tabs with viewpager swiping in android?

I've implemented nested tabs with view pager with no problems, but my problem is on the swiping part,
When I do the swiping action the main activity tabs will be switched, but I want the fragment to swipe instead. how can I achieve this?
I've tried implement main tab with tab host and fragment tabhost which doesn't have swiping feature at all, but that disabled whole swipe on the main and fragment together.
Instead of custom library you can try to use Bottom navigation view for bottom bar which has been added to version 25 of the Design Support Library. Here is an Article about it.
So android.support.design.widget.BottomNavigationViewin your activity together with android.support.design.widget.TabLayout and ViewPagerin fragment should work the way you want it to work. And this will also provide good UX (similar to one implemented in Google Plus App)
hello shaheen zahedi maybe it's possible please..with..below
just set bottom tab changed listener
like..
btnTab.setTabChangeListener(null);
You can disable view pager swiping on a particular ViewPager.
But I would suggest to not make 2 ViewPagers on the same screen.
Your bottom TabLayout and corresponding ViewPager can be replaced with BottomBar library.
I feel like it is wise to follow the Google Material guidelines. Not sure if you checked it out already...
Either way, here is what Google considers best practice for lateral navigation between tabs. Hope it helps!
I made a sample project with nested tab and fragment. may be it might help what is you looking for.
following link to download:
NestedTabWithFragment

Is it possible to implement a TabLayout with activities

I have a Tablayout kind of a bottom navigation, and I want that when the user clicks in a cardview that I have it sends him to another Tablayout but when that happens the bottom navigation does not appear anymore. That is only possible with activities right?
A TabLayout is just a view like any other. It can be inflated as a part of another view, or as the content view for a Fragment or an Activity. So, you're not restricted to using just an Activity with a TabLayout.
Now, if you want it so that when you click on a CardView you're taking to another screen without a TabLayout, you have a couple of options:
Open a new activity
Since this second Activity is going to have a different content view, it's not going to have the TabLayout from the first activity.
Hide the TabLayout and change the content surrounding the CardView
Since we're sticking with the first Activity, we're going to need to make all of our content changes to the views in the Activity. This means setting the visibility on the TabLayout to View.GONE and potentially lots of changes to the rest of the views depending upon what your layout contains.
I noticed that you didn't mention a ViewPager at all. Typically, this is what will be used with a TabLayout to swap between Fragments when you click on each tab. You could have all of your tabs' content in separate Fragments and then when you click on a CardView, just swap that tab's Fragment out for a different one and hide the TabLayout.
So, to answer your question, it is easier to just open a new activity, but it is possible to not use a second activity if you want to put in the work to modify your first one in runtime.

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