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:
In the future I'm going to need a bar like below (the style must be similar to see this link)
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.
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.
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.
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