采用支持-V7-应用程序兼容性搜索查看的动作条 [英] SearchView in ActionBar using support-v7-appcompat

查看:169
本文介绍了采用支持-V7-应用程序兼容性搜索查看的动作条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直很努力地获得搜索查看小部件使用支持-V7库的动作条扩大。我已经成功地得到它的工作,而不支持库时,我的目标,但4.0+我想写的应用为2.3+,所以我需要使用支持库。
我创建了以下menu.xml文件一个空白的新活动:

I've been trying very hard to get the SearchView widget to expand in the actionbar using the support-v7 libraries. I've managed to get it working without the support libraries when I target 4.0+ but I want to write the app for 2.3+ so I need to use the support libraries. I created a blank new activity with the following menu.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never"
    android:title="@string/action_settings"/>
    
<item
    android:id="@+id/action_search"
    android:icon="@android:drawable/ic_menu_search"
    yourapp:showAsAction="always"
    yourapp:actionViewClass="android.support.v7.widget.SearchView"
    android:title="Search"/>
</menu>

这甚至不显示的搜索按钮,更不用说扩大它在点击。它只需添加的搜索进入菜单,而不是显示在动作条吧。

This does not even show the search button, let alone expand it upon clicking. It simply add's the search into the menu instead of showing it in the actionbar.

另外我想没有应用程序兼容性库一样,我只是取代了menu.xml文件有:

Alternatively I tried the same without the appcompat library , I simply replaced the menu.xml with:

<item
    android:id="@+id/action_search"
    android:icon="@android:drawable/ic_menu_search"
    android:showAsAction="always"
    android:actionViewClass="android.widget.SearchView"
    android:title="Search"/>

和它工作完全正常,甚至扩展到在点击搜索文本输入小部件。

And it works perfectly fine, and even expands to the search text input widget upon clicking.

我要搜索查看如第二画面可同时使用应用程序兼容性库,但出于某种原因,它似乎并不奏效。我使用Eclipse和我已经包含在完全一样的的支持库设置[developer.android.com]

I want the searchview as available in the second picture while using the appcompat library, but for some reason it doesn't seem to be working. I'm using eclipse and I've included the Support libraries with resources exactly as specified in Support Library Setup[developer.android.com].

我的清单文件已minsdk版本7,targetsdk版本18和构建目标也是18。

My manifest file has minsdk version as 7, targetsdk version as 18, and the build target is also 18.

我怀疑的东西是在支持库设置不对劲,有人可以告诉我,我可能是做错了?谢谢!

I suspect something is amiss in the support library setup, can someone please tell me what I might be doing wrong? Thanks!

推荐答案

也许搜索查看并没有表现出因为你错过添加 collapseActionView 在这一行: yourapp:showAsAction =总是

Maybe SearchView wasn't showed because you missed to add a collapseActionView in this line: yourapp:showAsAction="always".

另外,你的活动必须扩展 AppCompatActivity 。因此,加应用程序兼容性库项目

Also, your activity must extends AppCompatActivity. So, add AppCompat library to project

更多的细节,你可以在此阅读链接

More details you can read on this link

希望它会帮助你。

这篇关于采用支持-V7-应用程序兼容性搜索查看的动作条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆