Man*_*uel 5 android coding-style menu transparent
在我的Android 2.2.2设备上,画廊看起来非常好.我想在自己的应用程序中做的是按一个按钮,然后显示如下所示的菜单:

这是使用任何标准的Android主题/样式?有没有人知道有这样一个菜单的示例代码?
编辑:我发现用一个Dialog可以模仿这个菜单.为了简化这个例子,我在这个例子中没有使用ListView,只是对话框的一个TextView条目:
<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>
Run Code Online (Sandbox Code Playgroud)
按下按钮时显示对话框:
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();
Run Code Online (Sandbox Code Playgroud)
这将创建一个靠近图片菜单的对话框.不过我还有两个问题:
1)如何在对话框底部绘制这个小三角形,如上图所示?
2)应该打开对话框的按钮水平放置在底部按钮栏的中间.因此,当我按下它时,对话框应显示在该按钮的正上方.我想做的是:
WMLP.x = middleButton.getLeft() + (middleButton.getWidth() / 2) - dialog.getWindow().getDecorView().getPaddingLeft() - (WMLP.width / 2);
Run Code Online (Sandbox Code Playgroud)
问题是,WMLP.width是-2.我想原因是布局宽度设置为"wrap_content"(即-2),此时不知道实际宽度.那么,我如何确定对话框的宽度,以便我可以将它同心放在另一个视图上?
更新:我终于找到了一个很好的对话源,如下所示:http: //www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/
这正是我想要的,我现在正在我的应用程序中使用它.
您可以通过在当前位置添加一个 PopupWindow 来完成此操作,为了绘制这个很酷的菜单,您将需要有这个背景的图像和要绘制的小箭头。
此外,您还应该阅读有关九路径可绘制的内容来完成此任务。
PS:我已经完成了这个,但是使用了另一张图像。