Skip to content Skip to sidebar Skip to footer

Add Edittext To Toolbar

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 He

Solution 1:

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>

Solution 2:

  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:

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

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

Solution 3:

Use belove code

       <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        app:titleTextColor="@color/colorAccent"
        app:theme="@style/ToolbarColoredBackArrow"
        app:subtitleTextColor="@color/colorAccent"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay">

        <TextView
            android:textColor="@color/colorAccent"
            android:text="June 14"
            android:textAllCaps="true"
            android:layout_gravity="right"
            android:layout_marginRight="11dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tv_daily" />

    </android.support.v7.widget.Toolbar>

Post a Comment for "Add Edittext To Toolbar"