2

I'v just updated my Android Studio to the latest version. This update comes with the support design library version 23.2.0

I'v used TabLayout with icon in my app (convert Drawable to SpannableString) and it works well with the support design library version 23.1.1 but not version 23.2.0.

Any ideas for this problem?

Hoang Lam
  • 523
  • 8
  • 23

3 Answers3

0

If you are overriding using TabLayout and overriding addTab(Tab), then override

public void addTab(Tab tab, boolean setSelected)

and

public void addTab(Tab tab, int position, boolean setSelected)

From the implementation you can see, that these two methods are not chained, so your code will only get called once, depending on which method the framework uses.

Looks like version 23.2.0 changed from invoking addTab(Tab) to addTab(Tab tab, boolean setSelected) directly

Jeppe Leth
  • 270
  • 4
  • 4
0

here is the answer for icons:

mTabLayout.setupWithViewPager(mViewPager);
// and then:
for (int i = 0; i < tabLayout.getTabCount(); i++) {
     tabLayout.getTabAt(i).setIcon(R.drawable.btn_add_card);
}

found here: Tablayout with icons only

Community
  • 1
  • 1
Pavel Biryukov
  • 1,076
  • 12
  • 19
0

I had the same problem after updating to Android Support Library 23.2.0 and later to 23.3.0.

After googling around without finding any answer I finally solved it myself. My solution was to update the icons directly after each time the notifyDataSetChanged() was invoked (and maybe you need it in more places) like below:

mSectionsPagerAdapter.notifyDataSetChanged();
mTabLayout.getTabAt(0).setIcon(R.drawable.tab_0_icon);
mTabLayout.getTabAt(1).setIcon(R.drawable.tab_1_icon);
mTabLayout.getTabAt(2).setIcon(R.drawable.tab_2_icon);
mTabLayout.getTabAt(3).setIcon(R.drawable.tab_3_icon);

The members used above is set in Activity's onCreate() like below:

...

private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
private TabLayout mTabLayout;

...

@Override
protected void onCreate(Bundle savedInstanceState) {

    ...

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    mTabLayout = (TabLayout) findViewById(R.id.tabs);
    mTabLayout.setupWithViewPager(mViewPager);

    mTabLayout.getTabAt(0).setIcon(R.drawable.tab_0_icon).select();
    mTabLayout.getTabAt(1).setIcon(R.drawable.tab_1_icon);
    mTabLayout.getTabAt(2).setIcon(R.drawable.tab_2_icon);
    mTabLayout.getTabAt(3).setIcon(R.drawable.tab_3_icon);

    ...
}