Reputation: 2168
I've seen a few posts about getting the title to show in actionbarsherlock along with the icon. The icon is displaying fine, but the title does not show beside it.
Currently it shows the home icon with all the tabs beside it. What I am looking for is the home icon, then title, and below all this have the tabs show. Here is my code.
ACTIVITY
public class MainActivity extends SherlockFragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mJsonHandler = JsonHandler.getInstance(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
ActionBar ab = getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(true);
ab.setDisplayShowTitleEnabled(true);
ab.setDisplayShowHomeEnabled(true);
ab.setDisplayUseLogoEnabled(true);
ab.setTitle("TITLE TO SHOW");
inflater.inflate(R.menu.activity_main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId()) {
case R.id.menu_item0:
break;
case R.id.menu_item1:
break;
case R.id.menu_item2:
break;
case R.id.menu_item3:
break;
case R.id.menu_item4:
break;
case R.id.menu_item5:
break;
default:
this.onBackPressed();
break;
}
return false;
}
}
activity_main.xml (for menu)
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_item0"
android:orderInCategory="1"
android:showAsAction="always"
android:title="@string/menu_item0"/>
<item
android:id="@+id/menu_item1"
android:orderInCategory="2"
android:showAsAction="always"
android:title="@string/menu_item1"/>
<item
android:id="@+id/menu_item2"
android:orderInCategory="3"
android:showAsAction="always"
android:title="@string/menu_item2"/>
<item
android:id="@+id/menu_item3"
android:orderInCategory="4"
android:showAsAction="always"
android:title="@string/menu_item3"/>
<item
android:id="@+id/menu_item4"
android:orderInCategory="5"
android:showAsAction="always"
android:title="@string/menu_item4"/>
<item
android:id="@+id/menu_item5"
android:orderInCategory="6"
android:showAsAction="always"
android:title="@string/menu_item5"/>
Manifest
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Sherlock.Theme" >
<activity
android:name=".activities.MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Sherlock Theme
<style name="Sherlock.Theme" parent="Theme.Sherlock.Light.DarkActionBar">
</style>
Upvotes: 0
Views: 1414
Reputation: 30804
You're setting too many menu items to always
show in the ActionBar
. You should only set the most important ones to do so. You should read through the Android Design Guidelines on the appropriate way to set up the ActionBar
Android Design Guidelines - Action Bar organization
Also, you should set up the ActionBar
in onCreate
and leave onCreateOptionsMenu
for only inflating your menu(s). This is just a general tip and goes towards better, more professional code formatting.
Upvotes: 3