充气弹出菜单项编程

编程入门 行业动态 更新时间:2024-10-27 19:30:06
本文介绍了充气弹出菜单项编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在活动中,pressing按钮赖以,下面的方法被调用 -

I have a button in my activity, pressing upon which, the following method gets called -

private ArrayList<ListView> myListViewList; private ArrayList<MyListAdapter> myAdapterList; public void onPopupButtonClick(View button) { Log.v(TAG, "onPopupButtonClick"); PopupMenu popup = new PopupMenu(this, button); Menu menu = popup.getMenu(); // how do i display the myListViewList as items of in this popup menu // i.e how do i inflate myListViewList into menu object? }

我知道如何为活动做编程方式 - 创建的活动的上下文linearlayouts和列表视图,最后用addContentView

I know how to do this programatically for an activity - creating linearlayouts and listViews and finally using addContentView on the activity's context.

但找到如上所述很难做同样的弹出式菜单中的场景。

But finding it hard to do the same for the popup menu scenario as described above.

任何帮助是极大AP preciated。

Any help is greatly appreciated.

TIA。

推荐答案

勾选此code的弹出式窗口

Check this code for Pop-up window

LayoutInflater inflater = (LayoutInflater) PopupMain.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View layout = inflater.inflate(R.layout.popup, (ViewGroup)findViewById(R.id.popup_menu_root)); PopupWindow pw = new PopupWindow(layout, 300,100, true); pw.dismiss(); pw.showAtLocation(layout, Gravity.BOTTOM, 0, 10);

和您的新弹出的布局应该如下:

And your New pop-up layout should be as follows :

Popup.xml:

Popup.xml :

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="schemas.android/apk/res/android" android:id="@+id/popup_menu_root" android:background="#FFFFFF" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="20dip" > <TextView android:id="@+id/popup_menu_button1" android:text="Copy" android:textColor="#000000" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>

这行决定新视图(弹出窗口)的高度和宽度

This line decide the Height and width of your New View(Pop up window)

PopupWindow pw = new PopupWindow(layout, 300,100, true);

和 pw.showAtLocation(布局,Gravity.BOTTOM,0,10);

告诉那里的弹出窗口显示应该..

tells where the Pop-up window should displays..

更多推荐

充气弹出菜单项编程

本文发布于:2023-08-06 03:35:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1309787.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹出   菜单项

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!