0

Anyone please tell me how to set image on tab here is my code

 ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    Tab tab = actionBar.newTab().setTabListener(new HomeTab());
    tab.setText(getResources().getString(R.string.tab_today));
    actionBar.addTab(tab);
user3409263
  • 117
  • 1
  • 4
  • 11
  • You can check this: [link1][1] [link2][2] [1]: http://stackoverflow.com/questions/4507718/ [2]: http://stackoverflow.com/a/5571787/1332870 – CompEng Apr 08 '14 at 08:15

3 Answers3

0

You can use setCustomView method. Here is sample code.

    LinearLayout llt = new LinearLayout(this);
    ImageView img = new ImageView(this);
    TextView txt = new TextView(this);
    img.setBackgroundResource(R.drawable.pic_00_00_00);
    txt.setText("aaaaa");
    llt.addView(img);
    llt.addView(txt);
    tab.setCustomView(llt);
0

you can use below code

tab.setIndicator("Tab Title",getResources().getDrawable(R.drawable.myicon))

where R.drawable.myicon is the image or selector saved in project resources

Syed Waqas
  • 862
  • 2
  • 9
  • 29
0

You can try with this code :

tab.setIcon(R.drawable.icon);

And make sure that icon.png image exists in the drawable folder.

user3506595
  • 129
  • 11