简体   繁体   English

下方具有滚动和EditText的弹出菜单

[英]popup menu with scroll and edittext below

I've a screen with a button that is placed somewhere on the screen (near the top). 我有一个带有按钮的屏幕,该按钮位于屏幕上的某个位置(靠近顶部)。

I would like to click on the button and get this result: A menu is opened right below the button and lets you choose text(from the list) or write my own text(where "type here.." is written). 我想单击该按钮并获得以下结果: 该按钮的正下方打开一个菜单,您可以从列表中选择文本或编写我自己的文本(其中写有“在此键入..”)。

在此处输入图片说明

I've this popup menu: 我有这个弹出菜单:

PopupMenu popupMenu = new PopupMenu(this, buttonChooseText);
    for (int i = 0; i < listDefaultText.size(); ++i) {
        // the list is from String type and contains "text1" and so on
        popupMenu.getMenu().add(listDefaultText.get(i);
    }
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getTitle().toString()) {
                case "Text1" :
                    //execute "text1" action
                    break;
                case "Text2" :
                    //execute "text2" action
                    break;
            }
            return false;
        }
    });
    popupMenu.show();

So how can I get this result? 那我怎么得到这个结果呢?

PopupMenu will likely fall short to meet your requirement since it doesn't offer much of flexibility in terms of comprising views other than menu item. PopupMenu可能无法满足您的要求,因为就组成菜单项以外的视图而言,它没有提供太多的灵活性。 Use PopupWindow instead as it supports custom layout. 请改用PopupWindow,因为它支持自定义布局。 Here is an example of it. 是一个例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM