搜索查看在动作条Appcompat [英] SearchView in Actionbar Appcompat

查看:132
本文介绍了搜索查看在动作条Appcompat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我使用 Theme.AppCompat.Light.DarkActionBar ,但我现在面临一个奇怪的问题。我在动作条创建搜索查看,并设置其属性应用程序:showAsAction =collapseActionView | ifRoom

In my application, I am using Theme.AppCompat.Light.DarkActionBar but I am facing a weird problem. I have created SearchView in ActionBar and has set its property app:showAsAction="collapseActionView|ifRoom"

但搜索查看未展开或折叠触摸。

but the SearchView is not expanded or collapsed on touch.

menu.xml文件

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/search"
        android:title="@string/search"
        android:icon="@android:drawable/ic_menu_search"
        app:showAsAction="collapseActionView|ifRoom"
        android:actionViewClass="android.support.v7.widget.SearchView" />
</menu>

我已经想尽了各种办法,但没有奏效。你知道吗?

I have tried different solutions but none worked. Any idea?

推荐答案

试图改变

android:actionViewClass="android.support.v7.widget.SearchView" 

 app:actionViewClass="android.support.v7.widget.SearchView"

这为我工作。

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      tools:context="com.ipartie.views.activities.HomeActivity">
      <item
          android:id="@+id/search"
          android:title="@string/search"
          android:icon="@drawable/abc_ic_search_api_mtrl_alpha"
          app:showAsAction="always"
          app:actionViewClass="android.support.v7.widget.SearchView"/>
</menu>

这篇关于搜索查看在动作条Appcompat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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