Dropdown buttons / Spinner like the ones on the design specs from Google

后端 未结 2 1171
北荒
北荒 2021-02-04 16:17

I\'m wondering how can I do a dropdown button / menu like the ones we can see in the designs specs from Google and in the image bellow, so the list expands bellow right bellow t

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 16:40

    You could use a PopUpMenu https://developer.android.com/reference/android/widget/PopupMenu.html

    PopupMenu popup = new PopupMenu(context, view);
    
    for (Element e: elementsList) {
    
        popup.getMenu().add(e.id).setTitle(e.title);
    }
    
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
    
         public boolean onMenuItemClick(MenuItem item) {
    
            return true;
         }
    });
    
    popup.show();
    

提交回复
热议问题