Skip to content Skip to sidebar Skip to footer

Tablayout Not Show Icon With Android Support Library 23.2.0

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

Solution 1:

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

publicvoidaddTab(Tab tab, boolean setSelected)

and

publicvoidaddTab(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

Solution 2:

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

Solution 3:

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:

...

privateSectionsPagerAdapter mSectionsPagerAdapter;
privateViewPager mViewPager;
privateTabLayout mTabLayout;

...

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {

    ...

    mSectionsPagerAdapter = newSectionsPagerAdapter(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);

    ...
}

Post a Comment for "Tablayout Not Show Icon With Android Support Library 23.2.0"