2012-02-10 3 views
1

Im new with the Android.иконки Android для Android не отображаются

Прямо сейчас Im пытается получить работу План табуляции. Ive сделал все так же, как в учебнике Android TabView, приложение работает нормально, но проблема в том, что я не вижу иконки, которые Ive определил в ic_tab_artists.xml. Есть только текст.

Я предполагаю, что это имеет какое-то отношение к теме, которая является по умолчанию одной или стилем или тем, что когда-либо было. Ive попытался изменить его, но он вообще не помог, все еще только текст.

Im, использующий Android SDK v4.03.

Я уверен, что есть достаточно гуру Android, которые помогут, поэтому заранее спасибо.

Это мой XML-определение с помощью иконки:

?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> 

И мой главный HolePage активность:

@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); 

} 

} 
+0

Вы можете оставить свой код? вы можете установить свои значки только по коду .. вы сделали это? – Hiral

+0

Конечно, если вы имеете в виду .xml, который определяет, какие значки загружать и когда> –

+0

, пожалуйста, отредактируйте ваш вопрос и введите код там! – Hiral

ответ

4

, не зная много подробно о темах, я обнаружил, что определение темы @android:style/Theme.NoTitleBar в манифест приложения решает проблему, и значки отображаются на вкладках.

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

Надеюсь, это поможет!

+0

Спасибо! Также помог мне. Самое странное - приложение отлично работало на Android 2.3. – user929298

Смежные вопросы