On my Android 2.2.2 device the gallery looks really nice. What I would love to do in my own app is to press a button and then show a menu that looks like this:
Is this using any standard Android themes / styles? Does anybody know of an example code to have a menu like this?
Edit: I figured out that one could mimic this menu with a Dialog. To simplify things I'm not using a ListView in this example, just a single TextView entry for the dialog:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
android:padding="10dp"
/>
</LinearLayout>
Showing the dialog when I press a button:
Dialog dialog = new Dialog(MyActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_dialog);
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Test option 1");
WindowManager.LayoutParams WMLP = dialog.getWindow().getAttributes();
WMLP.gravity = (Gravity.BOTTOM | Gravity.LEFT);
WMLP.x = 0;
WMLP.y = 0;
dialog.getWindow().setAttributes(WMLP);
dialog.show();
This creates a dialog that comes close to the menu in the picture. I still have two problems, however:
1) How can I draw this little triangle at the bottom of the dialog, like it is done in the picture above?
2) The button that is supposed to open the dialog is positioned horizontally in the middle of the bottom button bar. So when I press it, the dialog should be displayed right above that button. What I would like to do is this:
WMLP.x = middleButton.getLeft() + (middleButton.getWidth() / 2) - dialog.getWindow().getDecorView().getPaddingLeft() - (WMLP.width / 2);
The problem is, that WMLP.width is -2. I guess the reason is that the layout width is set to "wrap_content" (which is -2) and the actual width is not known at this moment. So, how can I determine the width of the dialog so that I can position it concentrical over another view?
Update: I finally found a great source for a dialog like this: http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/
It's exactly what I wanted and I'm using it in my app now.