我创建了一个带有TabHost和TabActivity的Android应用程序。在Android 2.3.4上,图标显示在我的选项卡上,但在Android 4.2.2上则没有。这是我的TabHost活动代码。并且所有图标都在res.drawable文件夹中。
@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {
private static MainActivity instance = null;
/**
* This is the IO Singleton Instance
*
*/
public static MainActivity sharedInstance(){
if (instance == null){
instance = new MainActivity();
}
return instance;
}
private TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabHost = getTabHost();
//Tab for Main Menu
TabSpec menuSpec = tabHost.newTabSpec("Home");
menuSpec.setIndicator("Home", getResources().getDrawable(R.drawable.main_menu));
Intent menuIntent = new Intent(this, MenuActivity.class);
menuSpec.setContent(menuIntent);
//Tab for Evacuation Routes
TabSpec evacSpec = tabHost.newTabSpec("Evacuation Routes");
evacSpec.setIndicator("Evacuation Routes", getResources().getDrawable(R.drawable.icon29));
Intent evacIntent = new Intent(this, EvacRouteTableActivity.class);
evacSpec.setContent(evacIntent);
//Tab for Shelters
TabSpec shelterSpec = tabHost.newTabSpec("Shelter Routes");
shelterSpec.setIndicator("Shelter Routes", getResources().getDrawable(R.drawable.shelter));
Intent shelterIntent = new Intent(this, ShelterActivity.class);
shelterSpec.setContent(shelterIntent);
//Tab for Fueling Stations
TabSpec fuelSpec = tabHost.newTabSpec("Refueling Routes");
fuelSpec.setIndicator("Refueling Routes", getResources().getDrawable(R.drawable.fillingstation));
Intent fuelIntent = new Intent(this, FuelStopActivity.class);
fuelSpec.setContent(fuelIntent);
//Tab for the Map
TabSpec mapSpec = tabHost.newTabSpec("Map");
mapSpec.setIndicator("Map", getResources().getDrawable(R.drawable.fillingstation));
Intent mapIntent = new Intent(this, MapViewActivity.class);
mapSpec.setContent(mapIntent);
tabHost.addTab(menuSpec);
tabHost.addTab(evacSpec);
tabHost.addTab(shelterSpec);
tabHost.addTab(fuelSpec);
tabHost.addTab(mapSpec);
}
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
}
public void addTabs(TabHost tHost){
//Tab for the Map
TabSpec mapSpec = tHost.newTabSpec("Map");
mapSpec.setIndicator("Map", getResources().getDrawable(R.drawable.fillingstation));
Intent mapIntent = new Intent(this, MapViewActivity.class);
mapSpec.setContent(mapIntent);
tHost.addTab(mapSpec);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
我的layout.xml文件
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"/>
</LinearLayout>
</TabHost>