There is a task to set the color of the tabs, depending on the event. There may be some tabs in one color, others in another. Those. The default method is to set the color for the selected tab and not for selected tabs. Therefore, I add my custom view, on top of the one in the tab. That view that is in taba as I understand cannot be obtained (if you do not use reflection). Here is my view:

<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:textColor="@color/colorTextDefault" android:textSize="15sp" /> 

And this is the code that is executed when creating tabs.

  TextView tv = (TextView) LayoutInflater.from(this).inflate(R.layout.tv_tab_item, null); for (int i = 0; i < count; i++) { tv.setText(++tabName + ""); TabLayout.Tab tab = tabLayout.newTab(); tab.setCustomView(tv); tabLayout.addTab(tab); } 

Tabs are obtained without names.

I tried to write at the end of the tabLayout.setupWithViewPager(mViewPager); Did not work. tried this:

 TextView tv = (TextView) LayoutInflater.from(this).inflate(R.layout.tv_tab_item, null); for (int i = 0; i < count; i++) { TabLayout.Tab tab = tabLayout.newTab(); tab.setCustomView(tv); TextView textView = (TextView) tab.getCustomView(); textView.setText(++tabName + ""); tabLayout.addTab(tab); tabLayout.setupWithViewPager(mViewPager); } 

And still there is no result. What did I do wrong?

  • I found errors, firstly, the text view is created outside the loop, and secondly something does not work through the inflighter, if you just write new TextView (context), then everything works. - Turalllb

0