My Toolbar
and EditText
look like this:
I tried adding it as an ActionView
but I got this result:
It basically just added my words 'Tap Below' as a title without the TextView
Here's what I did:
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
<?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>
I thought by doing this I add my EditText
layout to the Toolbar
...
Can someone please help?
Alternatively, is there a trick where I can overlay the EditText
on the Toolbar
?
I tried adding <item name="windowActionModeOverlay">true</item>
but it didn't do anything.
Use belove code
Just add the
EditText
to the XML for yourToolBar
. That is probably the easiest way.Add the EditText to the Toolbar xml.
Add the
Toolbar
to yourActivity's
xml layout, at the top.Set the toolbar as ActionBar:
This will make the toolbar "become" the
ActionBar
withEditText
inside.