图标未显示在标签的Tab中

时间:2013-08-21 19:40:59

标签: android icons fragment-tab-host

我遵循了本教程http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/

但是我需要显示图像,所以我将48x48 png文件复制到drawable-hdpi并在初始化主机中包含了代码行标签

        TabsFragmentActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator("Tab 1", getResources().getDrawable( R.drawable.photos_white)),
            ( tabinfo = new TabInfo("Tab1", TabFragment1.class, args)));
    TabsFragmentActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab2").setIndicator("Tab 2", getResources().getDrawable( R.drawable.photos_white)),
            ( tabinfo = new TabInfo("Tab2", TabFragment2.class, args)));
    TabsFragmentActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab3").setIndicator("Tab 3",getResources().getDrawable( R.drawable.photos_white) ),
            ( tabinfo = new TabInfo("Tab3", TabFragment3.class, args)));

我做错了什么?图标没有显示。

清晰的整个方法:

    private void initializeTabHost(Bundle args) {
    mTabHost = (TabHost)findViewById(android.R.id.tabhost);
    mTabHost.setup();
    TabInfo tabinfo = null;
    TabsFragmentActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator("Tab 1", getResources().getDrawable( R.drawable.photos_white)),
            ( tabinfo = new TabInfo("Tab1", TabFragment1.class, args)));
    TabsFragmentActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab2").setIndicator("Tab 2", getResources().getDrawable( R.drawable.photos_white)),
            ( tabinfo = new TabInfo("Tab2", TabFragment2.class, args)));
    TabsFragmentActivity.addTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab3").setIndicator("Tab 3",getResources().getDrawable( R.drawable.photos_white) ),
            ( tabinfo = new TabInfo("Tab3", TabFragment3.class, args)));
    this.mapTabInfo.put(tabinfo.tag,  tabinfo);
    this.onTabChanged("Tab1");
    mTabHost.setOnTabChangedListener(this);

}

1 个答案:

答案 0 :(得分:0)

原因是有些手机没有显示图标,显然我正在使用手机。我创建了一个带有图标和文本的视图,并使用了那个重载。