Android pop-up menu with icons (similar to Google Map app version 6)

Does anyone know which component is used for the menu in the new version 6 of the official Google Maps application for Android?

I am trying to create a menu similar to this, I can not find anything on the official pages of the developer (Note: I am targeting the Gingerbread API, possibly with backward compatibility up to 1.6.)

Here is the only image I found from this menu (this is on ICS, but something similar is displayed on Gingerbread). Look at the screenshot to the left here (from the Gizmodo website):

from gizmodo

If there is no built-in component, what approach would you use to create it?

In the worst case, if such a component does not exist for Android 2.x, do you know if the Google Map application itself is open source and where can I find its source?

+4
source share
4 answers

Just check out the following link. There are good examples of quick action dialogue. This way you can change the code for everything you want.

http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/

+2
source

This should work before API 4 (but not tested, YMMV). For instance:

An example

If you use ActionBarSherlock, you can use the IcsListPopupWindow class. Set some properties on it in onCreate. You will also need a subclass of ArrayAdapter.

in onCreate ():

 mPopupMenu = new IcsListPopupWindow(getContext()); mAdapter = new PopupMenuAdapter(this, android.R.layout.simple_list_item_1, yourArrayOfPopupMenuItems); mPopupMenu.setAdapter(mAdapter); mPopupMenu.setModal(true); mPopupMenu.setOnItemClickListener(this); mPopupMenu.setOnDismissListener(this); // only if you need it 

Inner classes inside your fragment / action:

 private class PopupMenuAdapter extends ArrayAdapter<PopupMenuItem> { Context context; int layoutResourceId; PopupMenuItem data[] = null; public PopupMenuAdapter(Context context, int layoutResourceId, PopupMenuItem[] data) { super(context, layoutResourceId, data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; // initialize a view first if (view == null) { LayoutInflater inflater = ((Activity)context).getLayoutInflater(); view = inflater.inflate(layoutResourceId, parent, false); } PopupMenuItem pItem = data[position]; TextView text = (TextView)view.findViewById(android.R.id.text1); text.setText(pItem.textResId); text.setCompoundDrawablesWithIntrinsicBounds(pItem.iconResId, 0, 0, 0); return view; } } // ... PopupMenuItem is just a container private static class PopupMenuItem { public int iconResId; public int textResId; public PopupMenuItem(int iconResId, int textResId) { this.iconResId = iconResId; this.textResId = textResId; } } 

Whenever you need to show it (e.g. in View.OnClickListener )

 mPopupMenu.setContentWidth(getActivity().getWindowManager().getDefaultDisplay().getWidth() / 2); PopupAdapter.notifyDataSetChanged(); // if you change anything mPopupMenu.setAnchorView(yourAnchorView); mPopupMenu.show(); 

In your OnItemClickListener

Be sure to call mPopupMenu.dismiss() !

Hope this helps! And thanks to Jake Wharton for the ABS!

+11
source

PopupMenu is probably what you are looking for. However, it only works on Android 3.0+ (represented at API level 11), and it is not present in the compatibility library, as far as I know.

+4
source

This is more like a custom action bar. Probably ActionProvider . ActionBar is available from API level 11, but check out ActionBarSherlock .

0
source

Source: https://habr.com/ru/post/1383862/


All Articles