Roh*_*wal 3 android optionmenu android-alertdialog android-dialog android-styles
我正在尝试实现flipkart 应用程序的操作栏功能。
.
为此,我已成功创建了一个自定义操作栏,但我在将菜单显示为溢出图标单击下拉菜单时遇到了问题。
如果我尝试在按钮上单击 Android 选项菜单,然后在我的屏幕底部中心获得没有图标的菜单 (4.2.2)。使用自定义对话框或警报对话框会淡化背景,它们也会出现在屏幕中央。
我应该怎么做才能获得与上图类似的功能?
小智 5
您可以轻松使用ListPopupWindow并为您提供任何方便adapter:
// create any adapter with any data, just as for ordinary ListView
SimpleAdapter simpleAdapter= new SimpleAdapter(this, dataSet, android.R.layout.simple_list_item_2,
new String[] {"Name", "Tel. no."},
new int[] {android.R.id.text1, android.R.id.text2});
ListPopupWindow listPopup = new ListPopupWindow(this); // feed context to ListPopupWindow
listPopup.setAdapter(simpleAdapter); // set adapter to created ListPopupMenu
listPopup.setAnchorView(findViewById(id));
// id - any id of any view on the screen. Under this view popup appears. It may be MenuItem as well
listPopup.setWidth(getWidestView(simpleAdapter));
// as popup width equals the anchor width, use getWidestView method for proper list displaying.
// ListPopupWindow.WRAP_CONTENT won't work here
listPopup.show();
Run Code Online (Sandbox Code Playgroud)
getWidestView你可以在这里找到片段:https : //stackoverflow.com/a/13959716/4890659
| 归档时间: |
|
| 查看次数: |
9583 次 |
| 最近记录: |