I want to have similar menu item functionality as in the chrome browser for mobile as it is in the picture. I want to have back, forward, refresh menu items in a single row. How can I implement a similar menu item? is there any reference or is there is any hack to bring this functionality?
My app is aimed only for tablets. Here is my current Action bar menu item:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/favorite"
android:showAsAction="always"
android:title="Happy"/>
<item
android:id="@+id/share_button"
android:icon="@drawable/share"
android:showAsAction="always"
android:title="Share"/>
<item
android:id="@+id/hola_button"
android:showAsAction="always"
android:title="Hola"/>
<item
android:icon="@drawable/more_actions"
android:showAsAction="always">
<menu>
<item
android:id="@+id/back_button"
android:icon="@drawable/back"
android:title="back"/>
<item
android:id="@+id/forward_button"
android:icon="@drawable/forward"
android:title="forward"/>
<item
android:id="@+id/refresh_button"
android:icon="@drawable/refresh"
android:title="refresh"/>
</menu>
</item>
</menu>
This looks like a customized Dialog with a listview and a custom listheader
OR
a listview below a simple layout with 3 buttons on top within a dialog.
You could show the same on the actionbar menu item click.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getSupportMenuInflater().inflate(R.menu.menu_items, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.show_dlg:
// Show your custom dialog
break;
}
return super.onOptionsItemSelected(item);
}
Also this tutorial would help as a reference for inflating custom menus http://www.codeproject.com/Articles/173121/Android-Menus-My-Way
EDIT:
This examples is as an OverflowMenu (since ABS ditched the overflow-theme). you can inflate any kind of layout-combinations. This class extends from PopUpWindow and doesn't use the typical onCreateOptions. It uses the ABS-CustomView and a PopUpWindow to create menu's.
From android reference: A popup window that can be used to display an arbitrary view. The popup window is a floating container that appears on top of the current activity.
The layout looks similar to your requested layout. This view is anchored to the ActionBar but you can display it anywhere you want. Popup window supports many show functions out of the box.
Customizable OverflowMenu
public class OverflowMenu extends PopupWindow {
private View mContentView;
public OverflowMenu(Context context, int resourceId) {
super(context);
mContentView = LayoutInflater.from(context).inflate(resourceId, null);
setContentView(mContentView);
setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
// Handle touchevents
setOutsideTouchable(true);
setFocusable(true);
setBackgroundDrawable(new BitmapDrawable());
}
/**
* Attach the OverflowMenu View to the ActionBar's Right corner
* @param actionBarView
*/
public void show(View actionBarView) {
int x = actionBarView.getMeasuredWidth() - mContentView.getMeasuredWidth();
showAsDropDown(actionBarView, x, 0);
}
/**
* Return mContentView,
* used for mContentView.findViewById();
* @return
*/
public View getView(){
return mContentView;
}
}
MainActivity
public class MainActivity extends SherlockActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mai n);
final ActionBar actionBar = getSupportActionBar();
actionBar.setCustomView(R.layout.actionbar);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
final OverflowMenu menu = new OverflowMenu(this,R.layout.menu_overflow);
final ImageButton overflowBtn = (ImageButton) actionBar.getCustomView().findViewById(R.id.actionbar_overflow);
overflowBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
menu.show(actionBar.getCustomView());
}
});
}
}
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