I have created a android App with a TabHost and TabActivity. On Android 2.3.4 the Icons appear on my tab but on Android 4.2.2 they do not. Here is my TabHost Activity code. And All the icons are in the res.drawable folder.
@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;
}
}
My layout.xml file
<?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>