質問

I followed this tutorial http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/

But I need images to show up, so I copied a 48x48 png file into drawable-hdpi and chnaged the tab line of code inside the Initialize host

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

What am I doing wrong? The icon doesn't show up.

The whole method for clarity:

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

}
役に立ちましたか?

解決

The reason is some phones do not show the icon and apparently I was using the phone. I created a view with an icon and text, and used that overload.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top