Viktor Szekeress
Viktor Szekeress

Reputation: 171

android Tab icons don't show up

Right now I'm trying to get the Tab layout to work. I've done everything just like in Android TabView tutorial, app runs ok, but the problem is that I dont see any icons that I've defined them in ic_tab_artists.xml. There is text only.

I guess it has something to do with theme that is default one or style or whatever. I've tried to change it but it didn't help at all, still just a text.

I'm using Android SDK v4.03.

I'm sure there are enough Android gurus that will help, so thanks in advance.

This is my .xml defining using icons:

?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">


    <!-- When selected, use grey -->
<item android:drawable="@drawable/ic_tab_artists_grey" 
      android:state_selected="true" /> 


    <!-- When not selected (default), use white-->  
<item android:drawable="@drawable/ic_tab_artists_white" />

</selector>

And my main HolePage Activity:

@SuppressWarnings("deprecation")
public class HolePage extends TabActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.hole_page);

    //TABS      

    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Reusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab

    // Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, HolePageScores.class);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("scores").setIndicator("Scores",
                      res.getDrawable(R.drawable.tab_scores_icons))
                  .setContent(intent);

    tabHost.addTab(spec);

    // Do the same for the other tabs - Info
    intent = new Intent().setClass(this, HolePageInfo.class);
    spec = tabHost.newTabSpec("info").setIndicator("Info",
                      res.getDrawable(R.drawable.tab_scores_icons))
                  .setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs - Top
    intent = new Intent().setClass(this, HolePageTop.class);
    spec = tabHost.newTabSpec("top").setIndicator("Top",
                      res.getDrawable(R.drawable.tab_scores_icons))
                  .setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs - Hole
    intent = new Intent().setClass(this, HolePageHole.class);
    spec = tabHost.newTabSpec("hole").setIndicator("Hole",
                      res.getDrawable(R.drawable.tab_scores_icons))
                  .setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs - Par
    intent = new Intent().setClass(this, HolePagePar.class);
    spec = tabHost.newTabSpec("par").setIndicator("Par",
                      res.getDrawable(R.drawable.tab_scores_icons))
                  .setContent(intent);
    tabHost.addTab(spec);

    //Set default tab2
    tabHost.setCurrentTab(1);

}

}

Upvotes: 1

Views: 2880

Answers (1)

Janos
Janos

Reputation: 856

without knowing much in depth about themes, i have discovered that specifying the theme @android:style/Theme.NoTitleBar in the application manifest solves the issue and the icons show up in the tabs.

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar" 
    >
    <!-- MANIFEST -->
</application>

Hope, that helps!

Upvotes: 4

Related Questions