Disable TabLayout

I had the same problem and I solved it disabling touch event on tabs with the following code: LinearLayout tabStrip = ((LinearLayout)mTabLayout.getChildAt(0)); for(int i = 0; i < tabStrip.getChildCount(); i++) { tabStrip.getChildAt(i).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); }

How to use TabLayout with ViewPager2 in Android

You have to use this TabLayoutMediator that mimics tabLayout.setupWithViewPager() and sets up the ViewPager2 with Tablayout. Otherwise, you will have to write your own adapter that will combine both parties. Its code will look like this in Kotlin TabLayoutMediator(tabLayout, viewPager) { tab, position -> tab.text = tabTitles[position] }.attach()

TabLayout tab selection

If you know the index of the tab you want to select, you can do it like so: TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); TabLayout.Tab tab = tabLayout.getTabAt(someIndex); tab.select(); This technique works even if you’re using the TabLayout by itself without a ViewPager (which is atypical, and probably bad practice, but I’ve seen it done).

ViewPager + RecyclerView issue in android

I see a lot of problems with your code, but let’s get your UI displaying the subcategories since that’s your main concern. Change the getItem in your adapter to this: @Override public Fragment getItem(int position) { ArrayList<SubcategoryModel> subcategories = filelist.get(position).getItems(); Log.v(“adapter”, “getitem” + String.valueOf(position)+subcategories.size()); return FirstFragment.create(position,subcategories); } What caused the problem: Let’s focus on ArrayList<SubcategoryModel> … Read more

Tab not taking full width on Tablet device [Using android.support.design.widget.TabLayout]

A “simpler” answer borrowed from Kaizie would just be adding app:tabMaxWidth=”0dp” in your TabLayout xml: <android.support.design.widget.TabLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” app:tabMaxWidth=”0dp” app:tabGravity=”fill” app:tabMode=”fixed” />

Change the font of tab text in android design support TabLayout

If you are using TabLayout and you want to change the font you have to add a new for loop to the previous solution like this: private void changeTabsFont() { ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0); int tabsCount = vg.getChildCount(); for (int j = 0; j < tabsCount; j++) { ViewGroup vgTab = (ViewGroup) vg.getChildAt(j); int … Read more

Changing the background color of a Tab in TabLayout (Android design support library) doesn’t occupy the entire tab space

Define a selector as a drawable, and also have a drawable for the selected/unselected states. For this solution, I started with the code from this answer, and then added the functionality that changes the background color for the current Tab. First, the selector, tab_background.xml in the drawable folder: <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:drawable=”@drawable/tab_background_selected” … Read more

How do I change a tab background color when using TabLayout?

What finally worked for me is similar to what @如果我是DJ suggested, but the tabBackground should be in the layout file and not inside the style, so it looks like: res/layout/somefile.xml: <android.support.design.widget.TabLayout …. app:tabBackground=”@drawable/tab_color_selector” … /> and the selector res/drawable/tab_color_selector.xml: <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:drawable=”@color/tab_background_selected” android:state_selected=”true”/> <item android:drawable=”@color/tab_background_unselected”/> </selector>

How do you create an Android View Pager with a dots indicator?

All we need are: ViewPager, TabLayout and 2 drawables for selected and default dots. Firstly, we have to add TabLayout to our screen layout, and connect it with ViewPager. We can do this in two ways: Nested TabLayout in ViewPager <androidx.viewpager.widget.ViewPager android:id=”@+id/photos_viewpager” android:layout_width=”match_parent” android:layout_height=”match_parent”> <com.google.android.material.tabs.TabLayout android:layout_width=”match_parent” android:layout_height=”wrap_content”/> </androidx.viewpager.widget.ViewPager> In this case TabLayout will be automatically … Read more