Reputation: 57
Hello Can someone help me
This is my android source code
private int[] tabIcons = {
R.drawable.ic_tab_gallery,
R.drawable.ic_tab_facebook,
R.drawable.ic_tab_instagram,
R.drawable.ic_tab_album
};
tabLayout = (TabLayout)findViewById(R.id.tabLayout);
viewPager = (ViewPager)findViewById(R.id.viewpager);
setupViewPager(viewPager);
tabLayout.setupWithViewPager(viewPager);
setupTabIcons();
And this is how i put icon in TabLayout item
private void setupTabIcons() {
tabLayout.getTabAt(0).setIcon(tabIcons[3]);
tabLayout.getTabAt(1).setIcon(tabIcons[1]);
tabLayout.getTabAt(2).setIcon(tabIcons[2]);
//tabLayout.getTabAt(3).setIcon(tabIcons[3]);
}
But after refreshing my viewPager all my tabLayout icons disappear. Thanks for your help.
Upvotes: 4
Views: 1154
Reputation: 15963
I had the same issue and I reassign the icons to tablayout after viewpager refresh.Like
for (int i = 0; i < tabLayout.getTabCount(); i++) {
tabLayout.getTabAt(i).setIcon(imageResId[i]);
tabLayout.getTabAt(i).setText(textResId[i]);
}
Another approach is to override getPageTitle method of Viewpager adapter as mentioned in this post.
Upvotes: 5