onOptionsItemSelected()在其上有一个actionLayout一套菜单项时,点击不叫 [英] onOptionsItemSelected() not called when clicking on menu item which has an actionLayout set on it
问题描述
在我的行动吧,我已经定义,可以通过下面的code显示文本DONE菜单项:
In my action bar, I have defined a menu item that can show text "DONE" by the code below:
menu.xml文件:
Menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/action_register_text"
android:actionLayout="@layout/action_done_text"
android:title="@string/action_done"
android:showAsAction="always"/>
</menu>
action_done_text.xml:
action_done_text.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/expand_activities_button"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:clickable="true"
android:focusable="true"
android:addStatesFromChildren="true">
<TextView
android:id="@+id/register_action_bar_done"
android:layout_width="53dp"
android:layout_height="35dp"
android:layout_gravity="center"
android:layout_marginRight="10dip"
android:gravity="center"
android:text="DONE" />
</FrameLayout>
我 onCreateOptionsMenu
在code正确实施,视图可以正确显示文本,但只是当我轻触DONE文本, onOptionsItemSelected
不叫。对我来说,它看起来像click事件无法识别。
I have onCreateOptionsMenu
implement properly in the code, and the view can show the text correctly, but just when I tap on the DONE text, onOptionsItemSelected
is not called. To me, it seems like the click event is not recognized.
我在想,如果上面的方法是不添加文本菜单项的好办法?
I was wondering if the above way is not a good way to add a text menu item?
推荐答案
如图使用此<一个href=\"http://stackoverflow.com/questions/11627892/onoptionsitemselected-not-called-when-using-actionlayout-sherlockactionbar\">onOptionsItemSelected不叫使用actionLayout(SherlockActionBar)时
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.map_menu, menu);
for (int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
if (item.getItemId() == R.id.menu_more) {
itemChooser = item.getActionView();
if (itemChooser != null) {
itemChooser.setOnClickListener(this);
}
}
}
return super.onCreateOptionsMenu(menu);
}
这篇关于onOptionsItemSelected()在其上有一个actionLayout一套菜单项时,点击不叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!