将EditText添加到工具栏 [英] Add EditText to Toolbar

查看:89
本文介绍了将EditText添加到工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ToolbarEditText看起来像这样:

我尝试将其添加为ActionView,但得到了以下结果:

I tried adding it as an ActionView but I got this result:

它基本上只是添加了我的单词在下面点击"作为标题,而没有TextView

It basically just added my words 'Tap Below' as a title without the TextView

这就是我所做的:

menu.xml

<menu>
    ... 
    ...
    <item
        android:id="@+id/edit_text_menu"
        android:orderInCategory="300"
        android:title="Tap Below"
        android:actionLayout="@layout/edit_text_layout"
        app:showAsAction="ifRoom|collapseActionView"
        />
</menu>

edit_text_layout.xml

edit_text_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/myEditText"
    android:background="#000000">

</EditText>

我认为通过这样做,我可以将EditText布局添加到Toolbar ... 有人可以帮忙吗?

I thought by doing this I add my EditText layout to the Toolbar... Can someone please help?

或者,有什么技巧可以将EditText覆盖在Toolbar上吗?

Alternatively, is there a trick where I can overlay the EditText on the Toolbar?

我尝试添加<item name="windowActionModeOverlay">true</item>,但是它什么也没做.

I tried adding <item name="windowActionModeOverlay">true</item> but it didn't do anything.

推荐答案

只需将EditText添加到ToolBar的XML中即可.那可能是最简单的方法.

Just add the EditText to the XML for your ToolBar. That is probably the easiest way.

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
      <EditText
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:id="@+id/myEditText"
         android:background="#000000" />
</android.support.v7.widget.Toolbar>

这篇关于将EditText添加到工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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