[android] TabLayout tab selection

If you are using TabLayout with viewPager then this helps you. You set the TabLayout with ViewPager in addOnpagelistener.

if you want to set the TabLayout position directly(not click on the Tab individual) try below code tabLayout.getTabAt(position_you_want_to_set).select()

   /* will be invoked whenever the page changes or is incrementally scrolled*/
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            tabLayout.getTabAt(position).select();
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to android-viewpager

TabLayout tab selection How to disable or enable viewpager swiping in android Android ViewPager with bottom dots What is the difference between FragmentPagerAdapter and FragmentStatePagerAdapter? Getting the current Fragment instance in the viewpager How to implement a ViewPager with different Fragments / Layouts Update Fragment from ViewPager Getting the error "Java.lang.IllegalStateException Activity has been destroyed" when using tabs with ViewPager Android Viewpager as Image Slide Gallery dynamically add and remove view to viewpager

Examples related to android-tablayout

How do I change a tab background color when using TabLayout? Text size of android design TabLayout tabs TabLayout tab selection

Examples related to android-design-library

Android design support library for API 28 (P) not working how to change color of TextinputLayout's label and edittext underline android How to change the new TabLayout indicator color and height Change EditText hint color when using TextInputLayout TabLayout tab selection FloatingActionButton example with Support Library How to change the floating label color of TextInputLayout Android TabLayout Android Design