Swipable Tabs activity and its title also swipable with back button

42 Views Asked by At

How can i display below mentioned tabs view with back button and cardview?

enter image description here

1

There are 1 best solutions below

0
Sushant Paudel On

First of all, if you want to use back Button on a Android phone you have to override onBackPressed() function in an Activity or a Context.

@Override
public void onBackPressed() {
   //TODO your code goes here!
}

If you want to swipe between pages from your ViewPager you have to create a view pager and use the index of the pages to swipe between them.

@Override
public void onBackPressed() {
    final ViewPager mViewPager = findViewById(R.id.viewPager);
    if (mViewPager.getCurrentItem() != 0) {
        mViewPager.setCurrentItem(0);
    } else {
        super.onBackPressed();
    }
}

Above mentioned code will swipe the ViewPager's page to the first page, if it is in any other page than the first one.