Android下拉列表框架(Spinner)的下拉选项列表

3
我希望能够创建如下的下拉列表: enter image description here 我正在尝试使用SherlockActivity和Spinner来实现,但我不知道该如何操作。
以下是我的简单代码,但是它并不符合我的要求:
Java
final Spinner spinnerSelectmenu = (Spinner)findViewById(R.id.actionbar_filemenu_selectmenu);
    String[] items = {"", "menu1", "menu2"};
    ArrayAdapter<String> spinnerMenuList = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, items);
    spinnerMenuList.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerSelectmenu.setAdapter(spinnerMenuList);

xml

<Spinner 
    android:id="@+id/actionbar_filemenu_selectmenu"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_alignParentRight="true"
    />

enter image description here


我认为那不是Spinner... - Pragnani
1个回答

2

android:spinnerMode="dropdown" 似乎是正确的选择,但据我所知,它只能在 API 11 及以上版本中使用。
其他来源说,你需要使用 Holo 主题才能将你的代码显示为下拉菜单。请参见https://dev59.com/dWvXa4cB1Zd3GeqPH04Z#13560603


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接