列表视图中福尔摩斯动作条行动溢出 [英] listview as action overflow in sherlock actionbar
问题描述
怎么办获得点击福尔摩斯行动listdropdown item.It应该是类似于创建微调。但是,我有这种方法的问题,因为我不希望所选择的项目将显示在actionbar.it应similatr行动overflow.Can任何的帮助我this.Thanks提前。
How to do get a listdropdown on clicking sherlock action item.It should be similar to creating spinner. But I have a problem with that approach as I dont want the selected item to be shown on the actionbar.it should be similatr to action overflow.Can any on help me on this.Thanks in advance.
推荐答案
您可以创建一个使用此类行为微调
(或 IcsSpinner $ C在菜单项的操作布局$ C>为
ActionBarSherlock
)。虽然你必须使用一个小技巧 - 隐藏当前选定的项目
You can create such behavior using Spinner
(or IcsSpinner
for ActionBarSherlock
) in action layout of a menu item. Though you have to use a little trick - hide the currently selected item.
创建菜单的xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/item1"
android:actionLayout="@layout/my_dropdown_action_layout"
android:showAsAction="always"/>
其中, RES /布局-V14 / my_dropdown_action_layout.xml
将包含(此版本用于本地操作栏):
Where res/layout-v14/my_dropdown_action_layout.xml
will contain (this version is used for native action bar):
<?xml version="1.0" encoding="utf-8"?>
<Spinner xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?attr/actionBarItemBackground"
android:id="@+id/spinner"/>
和 RES /布局/ my_dropdown_action_layout.xml
将包含(此版本用于 ActionBarSherlock
):
and res/layout/my_dropdown_action_layout.xml
will contain (this version is used for ActionBarSherlock
):
<?xml version="1.0" encoding="utf-8"?>
<com.actionbarsherlock.internal.widget.IcsSpinner
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?attr/actionBarItemBackground"
android:id="@+id/spinner"/>
使用 IcsSpinner
是要创造一个下拉微调。如果你使用 RES /布局-V14 / my_dropdown_action_layout.xml
布局默认版本(在 RES /布局/
) ,将不同的行为在Android 2.X(微调将是对话模式)。
Using IcsSpinner
is necessary to create a dropdown spinner. If you use res/layout-v14/my_dropdown_action_layout.xml
layout for the default version (in res/layout/
), it would behave differently on Android 2.x (the spinner would be in dialog mode).
现在,你必须用数据填充微调正常。只要创建一个活动
,你吹的菜单,是这样的:
Now you have to fill the spinner with data properly. Just create an Activity
where you inflate the menu, this way:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.my_menu, menu);
MenuItem menuItem = menu.findItem(R.id.item1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_layout, R.id.text, items);
adapter.setDropDownViewResource(R.layout.list_item);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// native ActionBar
Spinner sp = (Spinner) menuItem.getActionView();
sp.setAdapter(adapter);
} else {
// ActionBarSherlock
IcsSpinner sp = (IcsSpinner) menuItem.getActionView();
sp.setAdapter(adapter);
}
return super.onCreateOptionsMenu(menu);
}
现在来隐藏当前所选项目的伎俩。布局 RES /规划/ spinner_layout.xml
将包含这样的:
Now comes the trick of hiding the currently selected item. Layout res/layout/spinner_layout.xml
will contain this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@null">
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/text"
android:visibility="invisible"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/my_dropdown_icon"
android:background="@null"/>
</FrameLayout>
此方式,你看到一个图标,菜单项,你有下拉菜单。需要注意的是布局 RES /布局/ list_item.xml
必须包含一个的TextView
id为研究.id.text
了。
This way you see an icon as the menu item and you have the dropdown menu. Note that layout res/layout/list_item.xml
has to contain a TextView
with id R.id.text
too.
另外,您也可以使用类似的方法,您可以使用 ActionProvider
,而不是行动的布局。
Alternatively, you can use similar approach where you can use ActionProvider
instead of action layout.
和另一种解决方案是创建自定义窗口小部件类似下拉列表中微调
。
And another solution would be to create custom widget similar to dropdown Spinner
.
这篇关于列表视图中福尔摩斯动作条行动溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!