我按照本教程http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/
但是我需要显示图像,所以我将一个 48x48 png 文件复制到 drawable-hdpi 中,并在 Initialize 主机中更改了选项卡行代码
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);
}