Ravi Ranjan
Ravi Ranjan

Reputation: 69

How to add icon in tabs using drawable array

I have one activity with two fragments I am using Tabs .. It is working fine with the text in tabs . I want to add icons on the tabs here is the code snippet.

analytics.java

declaration

private String[] tabs = { "Resturant", "Market"};
int[] iconList = new int[]{R.drawable.attendance, R.drawable.analytics};

adding tabs

for (String tab_name : tabs) {
    actionBar.addTab(actionBar.newTab().setText(tab_name)
            .setTabListener(this));
    i++;
} 

Upvotes: 0

Views: 242

Answers (1)

Libin
Libin

Reputation: 17085

use this ..

    ActionBar.Tab tabA = actionBar.newTab();
    tabA.setIcon(R.drawable.ic_launcher);
    tabA.setText("Tab A");
    actionBar.addTab(tabA);

Upvotes: 1

Related Questions