Nested tabs with viewpager swiping in android?
Asked Answered
B

5

13

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. Description

Babylon answered 21/2, 2017 at 9:54 Comment(0)
T
5

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)

Titi answered 1/3, 2017 at 21:47 Comment(1)
Also you can simply add an activity with BottomNavigationView using File > New > Activity > Bottom navigation activity.Lactiferous
D
3

hello shaheen zahedi maybe it's possible please..with..below just set bottom tab changed listener like..

btnTab.setTabChangeListener(null);
Doc answered 21/2, 2017 at 9:56 Comment(5)
viewpager does not have setTabChangeListener method, this class only contains addOnPageChangeListener which I need to implement it for the sake of changing iconsBabylon
if you don't want to swipe than also add null on addOnPageChaneListenerDoc
setTabChangeListener is for tab not for viewpager if you don't want to change according to tab then set in null on tabchangelistenerDoc
that'll disable the whole swiping feature as I said I want the fragment to swipe insteadBabylon
if you don't want to swipe than yes.\Doc
I
1

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.

Indiscrete answered 24/2, 2017 at 17:12 Comment(1)
thanx for mentioning, but i've implemented Bottombar library and still, cannot get swipe action into fragment, what can I do?Babylon
O
1

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!

Overline answered 1/3, 2017 at 10:41 Comment(0)
Q
1

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

Quality answered 2/3, 2017 at 18:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.