Android ActionBarSherlock Top Bar

enter image description here

I want to have an action bar like foursquare. I need tabs like Friends, Explore and Me . In addition, above the tabs, I want to have my own layout, which includes several buttons, such as a four-digit logo, update and registration in a four-digit one. I created tabs but could not change the layout above the tabs in the ActionBarSherlock. How can I solve this problem?

+5
source share
2 answers

To get a Foursquare view, you donโ€™t need to think about creating a layout over tabs. When using the Actionbar Sherlock you only need to worry:

  • Create a background for the top bar
  • menu.xml, ActionbarSherlock , ( , Actionbar thw).

, 1. 2. styles.xml( res) :

<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>

3. , , menu.xml( ( , res)):

<?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>

, , , - :

@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;
}
+7

(, ,...), onCreateOptionsMenu () .

:

"" /my _menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/refresh"
        android:icon="@drawable/ic_menu_refresh"
        android:title="refresh"
        android:showAsAction="always">
    </item>

</menu>

( ):

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
  MenuInflater inflater = getSupportMenuInflater();
  inflater.inflate(R.menu.my_menu, menu);

  // Allow activity and fragments to add items
  super.onCreateOptionsMenu(menu);

  return true;
}

, , onOptionsItemSelected ( MenuItem):

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
  switch (item.getItemId())
  {
    case android.R.id.refresh :
      // refresh your data...
      return true;

    default :
      return super.onOptionsItemSelected(item);
  }
}
+3

All Articles