JosephG JosephG - 14 days ago 6
Android Question

Icon on tabs not working

the icons on my tabs is not showing how i wanted them to be. I wanted the to be icons from my drawable folders but when I'm calling it. It returns numbers not icons.
Here is my code.

@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return ""+R.drawable.car2;
case 1:
return "Pending Cars";
case 2:
return "Currently Rented";
case 3:
return "Drivers";
}
return null;
}
}


the
return ""+R.drawable.car2;
suppose to return me an icon if I'm not mistaken right? But it returns me
2130837582
. Thanks for the help sirs. :)

Answer

Please check it:--

final int[] ICONS = new int[]{
        R.drawable.icon_1,
        R.drawable.icon_2,
        R.drawable.icon_3
};

//Get reference to your Tablayout
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);

tabLayout.getTabAt(0).setIcon(ICONS[0]);
tabLayout.getTabAt(1).setIcon(ICONS[1]);
tabLayout.getTabAt(2).setIcon(ICONS[2]);