I’m implementing the SherlockActionBar for an Android application, but I wanna maintain a backward compatibility with pre Honeycomb devices.
This is the sample code:
package com.sherlockbar.example;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.widget.TextView;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockActivity;
public class SherlockExampleActivity extends SherlockActivity implements ActionBar.TabListener {
private TextView mSelected;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_navigation);
mSelected = (TextView) findViewById(R.id.text);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
for (int i = 1; i <= 3; i++) {
ActionBar.Tab tab = getSupportActionBar().newTab();
tab.setText("Tab " + i);
tab.setTabListener(this);
getSupportActionBar().addTab(tab);
}
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction transaction) {
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction transaction) {
mSelected.setText("Selected: " + tab.getText());
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction transaction) {
}
}
For 4.0 devices this works perfect, but for Honeycomb it doesn’t work -I get the following error:
E/AndroidRuntime(2363): Caused by: java.lang.IllegalStateException:
You must use Theme.Sherlock, Theme.Sherlock.Light,
Theme.Sherlock.Light.DarkActionBar, or a derivative.
In the manifest I tried to establish that them but it’s not in the suggested list, plus if I write it, I still get the error.
How do I set the bar up for Honeycomb devices please?
Thanks a lot in advance!
Are you compiling against 4.0? You need to target the Android 4.0 sdk in order for it to compile correctly (even if you’re running on < 4.0).