如何添加在材料设计工具栏上的搜索按钮 [英] How to add search button on toolbar in material design
本文介绍了如何添加在材料设计工具栏上的搜索按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想加上左侧搜索按钮的设置弹出,但我无法在工具栏添加。
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:程序=http://schemas.android.com/apk/res-auto&GT;
菜单中的标签
这篇关于如何添加在材料设计工具栏上的搜索按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文