I set up ABS with a simple Android project and can’t find out why no single part of the action bar shows up on 2.3.3 (left), but works perfectly on 4.0 (right: title, tabs and menu).

What I did:
- Created new Android Project in Eclipse
- Added
android:theme="@style/Theme.Sherlock"in<application> <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />- Changed Java compliance to 1.6 (don’t think this matters, should be the default anyway)
- Added
- Added ABS as library project (compiled against SDK version 15 as well)
- Did not add support library to my project (doesn’t make a difference if I do)
Note: I have to use static attachment so I cannot extend one of the Sherlock* classes.
Source code:
package de.andidog.testthesherlock;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import com.actionbarsherlock.ActionBarSherlock;
import com.actionbarsherlock.ActionBarSherlock.OnCreateOptionsMenuListener;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
public class TestTheSherlockActivity extends Activity implements ActionBar.TabListener, OnCreateOptionsMenuListener
{
protected ActionBarSherlock sherlock = ActionBarSherlock.wrap(this);
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
sherlock.setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
showTabsNav();
// TODO: check order of these statements
sherlock.setContentView(R.layout.main);
setContentView(R.layout.main);
}
private void showTabsNav()
{
final ActionBar ab = sherlock.getActionBar();
ab.setDisplayUseLogoEnabled(true);
for(int i = 0; i < 5; ++i)
ab.addTab(ab.newTab().setIcon(R.drawable.ic_launcher).setTabListener(this));
ab.setDisplayShowHomeEnabled(true);
ab.setDisplayShowTitleEnabled(true);
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu)
{
return sherlock.dispatchCreateOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
menu.add("Refresh").setIcon(android.R.drawable.ic_menu_rotate).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true;
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft)
{
Log.d("TestTheSherlockActivity", "TAB RESELECTED");
}
@Override
public void onTabSelected(Tab tab, android.support.v4.app.FragmentTransaction ft)
{
Log.d("TestTheSherlockActivity", "TAB CLICKED");
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft)
{
Log.d("TestTheSherlockActivity", "TAB UNSELECTED");
}
}
My AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.andidog.testthesherlock"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock" >
<activity
android:name=".TestTheSherlockActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
How do I get this to work on 2.x?
Remove the second
setContentViewcall, this is overwriting the layout inflated by ABS.You should only be using the static attachment technique if you require extending from a non-Android base class. Otherwise it’s much easier to extend from
SherlockActivity(or any of the others).