I am using the TabLayout from Android Design support library. I am using material design theme. Below is the code
activity_scrollable_Tab.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabMode="scrollable"/> </android.support.design.widget.AppBarLayout> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </android.support.design.widget.CoordinatorLayout>
scrollableTabActivity.java
public class ScrollableTabsActivity extends AppCompatActivity { private Toolbar toolbar; private TabLayout tabLayout; private ViewPager viewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_scrollable_tabs); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); viewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(viewPager); tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); } private void setupViewPager(ViewPager viewPager) { ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); adapter.addFrag(new OneFragment(), "ONE"); adapter.addFrag(new TwoFragment(), "TWO"); ..... adapter.addFrag(new TenFragment(), "TEN"); viewPager.setAdapter(adapter); } class ViewPagerAdapter extends FragmentPagerAdapter { private final List<Fragment> mFragmentList = new ArrayList<>(); private final List<String> mFragmentTitleList = new ArrayList<>(); public ViewPagerAdapter(FragmentManager manager) { super(manager); } @Override public Fragment getItem(int position) { return mFragmentList.get(position); } @Override public int getCount() { return mFragmentList.size(); } public void addFrag(Fragment fragment, String title) { mFragmentList.add(fragment); mFragmentTitleList.add(title); } @Override public CharSequence getPageTitle(int position) { return mFragmentTitleList.get(position); } } }
Tab scrolling is working in Lollipop. But the same code is not working on Kitkat and Jelly bean devices. On Kitkat and Jelly bean device I face two problem,
When I scroll the Tab, Tab is scrolling along with page navigation in Jellybean and kitkat devices, but in Lollipop Tab alone gets scroll and it is working file. For eg: if 1,2,3..10 are the Tab and if I scroll the Tab, it scroll and for each scroll the Layout gets navigated. If I scroll, Tab gets navigate to 2nd Tab and then 3rd and so on.
Up navigation is not working in Jellybean and Kitkat devices. If I swipe the Toolbar, Tab scrolling is happening with page navigation (above-mentioned issue).
Can anyone tell me what could be the problem and in which portion I need to check and sort it. I can send APK file if provide me the email for a better understanding of the problem.
I am new to android, need some help to fix this.