I want to have an Action Bar like foursquare. What I want is tabs such as Friends, Explore and Me. Also, above the tabs I want to have a custom layout that includes some buttons such as foursquare logo, Refresh and Check-In in foursquare. I created tabs but I could not change the layout above tabs in ActionBarSherlock. How can I solve this problem?
ActionBarSherlock is deprecated. No more development will be taking place. For an up-to-date action bar backport use AppCompat. Thanks for all your support! ActionBarSherlock is an standalone library designed to facilitate the use of the action bar design pattern across all versions of Android through a single API.
Android ActionBar was launched by Google in 2013 with the release of Android 3.0 (API 11). Before that, the name of this top most visual element was AppBar. AppBar contains only the name of the application or current activity.
For an up-to-date action bar backport use AppCompat. Thanks for all your support! ActionBarSherlock is an standalone library designed to facilitate the use of the action bar design pattern across all versions of Android through a single API. The library will automatically use the native ActionBar implementation on Android 4.0 or later.
As mentioned earlier, every android app contains an ActionBar by default. This pre-included ActionBar display title for the current activity that is managed by the AncdroidManifest.xml file. The string value of the application’s title is provided by @string/app_name resource present under the application nodes.
To achieve a Foursquare look you do not need to be thinking of creating a layout above the tabs. When using Actionbar Sherlock you only need to worry about:
So, for 1. and 2. it's all about using styles.xml file (should reside in the values folder in the res folder) like so:
<style name="Theme.Example" parent="Theme.Sherlock">
<item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
<item name="absForceOverflow">true</item>
</style>
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.ActionBar.Solid">
<item name="background">@drawable/actionbar_background</item> <-- the background for top bar
<item name="icon">@drawable/actionbar_logo</item> <-- the logo that goes top left in the top bar
<item name="backgroundSplit">@drawable/bg_striped_split</item> <-- the image used between the menu items
</style>
For 3. all you need to do is create menu items under menu.xml (should reside in the menu folder (if not there, create one in the res folder)):
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_prefs"
android:icon="@drawable/settings_icon"
android:title="Preferences"
android:showAsAction="ifRoom" />
</menu>
The last thing you have to do to see the menu items is use these functions in the activity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
public boolean onOptionsItemSelected (MenuItem item) {
Intent intent;
switch (item.getItemId())
{
case R.id.menu_prefs:
// Launch Preference Activity
intent = new Intent(getBaseContext(), Preferences.class);
startActivity(intent);
break;
}
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With