Add EditText to Toolbar

  1. Add the EditText to the Toolbar xml.

  2. Add the Toolbar to your Activity's xml layout, at the top.

  3. Set the toolbar as ActionBar:

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }
    

This will make the toolbar "become" the ActionBar with EditText inside.


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>