我们可以在我们的菜单中有一个编辑文本框,在操作栏中显示如果可以,那么如何在编辑文本上获得点击事件呢
我找到了解决方案。它是这样做的(仅适用于android 3.0 honeycomb)在操作栏中放置编辑文本放置物品在你的菜单项中使用这个标签xml
android:actionLayout="@layout/search_bar"
定义编辑文本&按钮。
现在让监听器像这样做in onCreateOptionsMenu()
et = (EditText) menu.findItem(R.id.search_bar).getActionView().findViewById(R.id.searchbar);
findBtn = (ImageButton)menu.findItem(R.id.search_bar).getActionView().findViewById(R.id.find);
,然后为这些项放置侦听器。
您可以在操作栏中添加搜索栏,但不能作为菜单项…你说的"作为菜单项"是什么意思?
我还没有尝试过,但你能使用actionlayout从代码吗?在这种情况下,你可以这样使用get文本框:
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
LinearLayout wrapper = (LinearLayout) inflater.inflate(R.layout.random_layout, null);
EditText editText = (EditText )wrapper.findViewById(R.id.edit);
//
//code to set the listener
//
//
//set the android:actionLayout to wrapper etc.
//
我在工作,所以我不能做一些研究,所以这只是猜测…