工具栏图标消失了

工具栏图标消失了

本文介绍了在Android中展开SearchView后,工具栏图标消失了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

这是我的问题:

我有一个不错的工具栏,带有横向模式下的图标:

I have that nice toolbar with the icons in landscape mode:

展开搜索视图并显示弹出菜单后,出现添加"项(我认为不应该这样):

after expanding the search view and showing the popup menu the "add" item appears (I thought that it shouldn't):

然后按返回箭头键返回,如您所见,添加按钮出现:

then returning with the back arrow key, as you see, the add button goes:

,您将不再在弹出菜单中找到它:

and you won't find it in the popup menu anymore:

我正在使用support:appcompat-v7:25.1.0,这是我的菜单代码:

I'm using support:appcompat-v7:25.1.0, and here's my menu code:

    <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/app_bar_search"
        android:actionViewClass="android.support.v7.widget.SearchView"
        android:icon="@drawable/ic_action_search"
        android:title="Search"
        app:showAsAction="always|collapseActionView"
        android:enabled="true"
        android:visible="true"
        app:actionViewClass="android.support.v7.widget.SearchView"/>
    <item android:title="Add"
        android:enabled="true"
        android:icon="@drawable/ic_action_add"
        android:visible="true"
        app:showAsAction="ifRoom"
        android:id="@+id/add" />
    <item android:title="Settings"
        android:id="@+id/settings"
        app:showAsAction="never"
        android:icon="@drawable/ic_action_settings"
        android:enabled="true"
        android:visible="true" />
    <item android:title="Feedback"
        android:id="@+id/feedbvack"
        app:showAsAction="never"
        android:icon="@drawable/ic_action_feedback"
        android:enabled="true"
        android:visible="true" />

</menu>

我可以将添加按钮showAsAction设置为"always",但我不建议这样做.这里有人知道为什么会有这种行为吗?以及如何预防呢?

I can set the add button showAsAction to "always" but I know that this is discouraged.Does anyone here know why is there this behavior? and how can I prevent that?

谢谢.

推荐答案

尝试一下

<item
    android:id="@+id/app_bar_search"
    android:actionViewClass="android.support.v7.widget.SearchView"
    android:icon="@drawable/ic_action_search"
    android:title="Search"
    app:showAsAction="always|collapseActionView"
    android:enabled="true"
    android:visible="true"
    app:actionViewClass="android.support.v7.widget.SearchView"/>
<item android:title="Add"
    android:enabled="true"
    android:icon="@drawable/ic_action_add"
    android:visible="true"
    app:showAsAction="always"
    android:id="@+id/add" />
<item android:title="Settings"
    android:id="@+id/settings"
    app:showAsAction="never"
    android:icon="@drawable/ic_action_settings"
    android:enabled="true"
    android:visible="true" />
<item android:title="Feedback"
    android:id="@+id/feedbvack"
    app:showAsAction="never"
    android:icon="@drawable/ic_action_feedback"
    android:enabled="true"
    android:visible="true" />

app:showAsAction设置为always以确保它始终可见.

Set app:showAsAction to always to make sure it will be visible always.

这篇关于在Android中展开SearchView后,工具栏图标消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 18:05