android标签图标不显示 [英] android Tab icons don't show up

查看:103
本文介绍了android标签图标不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正试图让Tab布局工作。我已经做了一切,就像Android TabView教程一样,app运行正常,但问题是我没有看到任何我在ic_tab_artists.xml中定义它们的图标。只有文字。

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.

我正在使用Android SDK v4.03。

I'm using Android SDK v4.03.

我确信有足够的Android大师可以提供帮助,所以提前谢谢。

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

这是我的.xml定义使用图标:

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>

我的主要HolePage活动:

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

}

}


推荐答案

在不深入了解主题的情况下,我发现在应用程序清单中指定主题 @android:style / Theme.NoTitleBar 可以解决问题并且图标显示在选项卡中。

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>

希望,这有帮助!

这篇关于android标签图标不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆