Search code examples
androidandroid-activityactionbarsherlock

android using slidingmenu and actionbarsherlock together


I am new to android development, here is a simple question I have met when I am practicing sliding menu lib (https://github.com/jfeinstein10/SlidingMenu) and ActionBarSherlock lib.

I have my MainActivity extended SlidingActivity to have sliding menu feature:

public class ActivityMain extends SlidingActivity implements TabListener {

// 80 offset in pixels
private static final int LeftSlidingMenuOffset = 80;

private ActionBarDrawerToggle mDrawerToggle;

private ActionBar mActionBar;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    // set left slide menu
    setBehindContentView(R.layout.view_left_slide_menu);

    // initialize left slide menu property
    initalizeLeftDrawer();
}

But also in this activity, I want to have sherlock actionbar as well. According to some tutorial, I will need to extend SherlockActivity.
So what will be a good solution when we want to extend from two types of activities? Should I use fragment in this case?

Thank you


Solution

  • SlidingActivity already has ActionBar in it.

    You can get its instance from

    this.getActionBar()
    

    If you want your own custom view as the actionbar then use

    getActionBar().setCustomView(getCustomActionBar().build(), layout); 
    

    here getCustomActionBar.build() gives me the custom action bar view I have created

    There are many other methods you could use. Let me know if this solves your problem.