Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing an ActionBar using ActionbarSherlock and jeremyfeinstein slidingmenu

I have an action sherlock bar and I need customize this control as the following picture. I need a pseudocode or similar simple example. I downloaded the library, examples, and I have been searching in this site and google, but I could not find something like this. Sorry if the information is incomplete, in that case I'll edit the post with the information you need. Thanks.

Note:

  1. I do not want to use android.support.v4.widget.DrawerLayout, ActionBarDrawerToggle. I need the sherlock slide effect.
  2. I need a image and label above the list of menu options (LISTVIEW) (see the right image).

enter image description here

In the future I'm going to need a bar like below (the style must be similar to see this link)

enter image description here

like image 232
Gaston Flores Avatar asked May 13 '14 23:05

Gaston Flores


3 Answers

SidingMenu layout:

You should set a ListView as menu layout. Next, create sliding_menu_header.xml layout with ImageView and TextView inside:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageView
            android:src="@drawable/image_source"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    <TextView
            android:text="text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

</LinearLayout>

Now, you can inflate this layout and set it as ListView's header view:

View menuHeader = getLayoutInflater().inflate(R.layout.sliding_menu_header, null);
mListView.addHeaderView(menuHeader);
mListView.setAdapter(mYourMenuAdapter);

ActionBar layout:

You can add a custom view to the ActionBar. In your case the layout can be like:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="horizontal" >

    <Button
            android:id="@+id/button1"
            android:text="button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    <Button
            android:id="@+id/button2"
            android:text="button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

</LinearLayout>

Then add below lines to your onCreate method:

ActionBar actionBar = getSupportActionBar();
actionBar.setCustomView(R.layout.actionbar_view);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM
        | ActionBar.DISPLAY_SHOW_HOME);

Button button1 = actionBar.getCustomView.findViewById(R.id.button1);
Button button2 = actionBar.getCustomView.findViewById(R.id.button2);

Hope it will be helpful to you. If my answer is incomplete please comment and I'll update it.

like image 135
erakitin Avatar answered Sep 18 '22 15:09

erakitin


Implement "Sliding Menu" it's perfect with Sherlock ActionBar

Link library

https://github.com/jfeinstein10/SlidingMenu

VideoTutorial for implement two libraries

https://www.youtube.com/watch?v=IW6idyV0CZQ

EDIT

//pre-ICS
if (actionBarSherlock instanceof ActionBarImpl) {
    enableEmbeddedTabs(actionBarSherlock);

//ICS and forward
} else if (actionBarSherlock instanceof ActionBarWrapper) {
    try {
        Field actionBarField = actionBarSherlock.getClass().getDeclaredField("mActionBar");
        actionBarField.setAccessible(true);
        enableEmbeddedTabs(actionBarField.get(actionBarSherlock));
    } catch (Exception e) {
        Log.e(TAG, "Error enabling embedded tabs", e);
    }
}

//helper method
private void enableEmbeddedTabs(Object actionBar) {
    try {
        Method setHasEmbeddedTabsMethod = actionBar.getClass().getDeclaredMethod("setHasEmbeddedTabs", boolean.class);
        setHasEmbeddedTabsMethod.setAccessible(true);
        setHasEmbeddedTabsMethod.invoke(actionBar, true);
    } catch (Exception e) {
        Log.e(TAG, "Error marking actionbar embedded", e);
    }
}

look that link:

https://groups.google.com/forum/#!topic/actionbarsherlock/hmmB1JqDeCk

When you had tabs on your action bar you can asing one style for your tabs, border, backgroundImage, gravity and you give button appearance.

Look:

http://www.silverbaytech.com/2013/05/13/themes-for-the-android-actionbar-tabs/

Try it and tell us.

like image 34
Aspicas Avatar answered Sep 20 '22 15:09

Aspicas


From your picture it seams you want to scroll the actionbar too. That's not possible (to my knowledge). For something like that to work you have to make your custom actionbar (as a ordinary layout) and handle the visibility change and scroll by yourself. You can also check actionbar_compat (appcompat_v7). if basically offers the same functionality as ActionbarSherlock and SlidingMenu combined. http://android-developers.blogspot.ro/2013/08/actionbarcompat-and-io-2013-app-source.html. And the menu can contain heterogenous items, if that's your concern.

like image 35
Cristian Radu Avatar answered Sep 20 '22 15:09

Cristian Radu