0

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. :)

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
JosephG
  • 21
  • 5

2 Answers2

0

R.drawable.car2 - is not an icon - it's resource ID and it's int. You should use this ID to get icon drawable from resources:

Drawable icon = getResources().getDrawable(R.drawable.car2);
Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
0
 tablayout= (TabLayout) findViewById(R.id.tab_layout);
 tablayout.addTab(tablayout.newTab().setText().setIcon(R.drawable.icon1));
 tablayout.addTab(tablayout.newTab().setText().setIcon(R.drawable.icon2));
 tablayout.addTab(tablayout.newTab().setText().setIcon(R.drawable.icon3));