如何添加在材料设计工具栏上的搜索按钮按钮、栏上、材料、工具

2023-09-08 09:48:16 作者:守护貓咪的魚兒

我想加上左侧搜索按钮的设置弹出,但我无法在工具栏添加。

I am trying to add search button on left side of settings pop up but i am not able to add in toolbar.

下面是menu.xml文件我的code:

Here is my code of menu.xml :

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.example.materialtheme.MainActivity" >

    <item
        android:id="@+id/action_search"
        android:icon="@drawable/ic_launcher"
        android:menuCategory="secondary"
        android:showAsAction="ifRoom"
        android:title="@string/action_search"/>
    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_settings"/>

</menu>

和这里是我的toolbar.xml:

and here is my toolbar.xml :

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:elevation="4dp"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

我得到的工具栏,但没有得到搜索按钮?

I am getting toolbar but not getting search button ?

推荐答案

使用应用:showAsAction =总是您menu.xml文件的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto&GT; 菜单中的标签