How to properly add custom view to the toolbar?

I am using toolbar with extended height (56dp + 80dp) and want to add EditText to the bottom of the toolbar. The problem I have is that EditText DOES NOT expands itself to the right edge, like in picture below:

enter image description here

  • Android: Launch activity from clickable text
  • RecyclerView: find last visible item immediately after view created
  • Android studio 2.3 canary missing 'Launch Standalone SDK Manager' option in 'SDK Manager'
  • How can I print/log entire body contents of MultiPartEntity that is being used by HTTPRequest?
  • Unable to execute dex: Multiple dex files define Lcom/google/android/gms/analytics/internal/Command
  • Android: Conversion to Dalvik format failed: Unable to execute dex: null
  • The code looks like below:

    toolbar_edit_text.xml

    <?xml version="1.0" encoding="utf-8"?>
    <EditText xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Title"
        android:singleLine="true" />
    

    Adding layout to toolbar:

    LayoutInflater inflater = LayoutInflater.from(mActivity.getActionBarToolbar().getContext());
        mToolbarLayout = (EditText) inflater.inflate(R.layout.toolbar_edit_text, null);
        Toolbar.LayoutParams layoutParams = new Toolbar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.gravity = Gravity.BOTTOM;
        mActivity.getActionBarToolbar().addView(mToolbarLayout, layoutParams);
    

    Related posts:

    How can I maintain fragment state when added to the back stack?
    Date and time formatting depending on locale
    Google Play URL messes up Facebook&#039;s share dialog
    API to get android google play reviews(Getting device name and app version)
    what are the file formats can android video player supports in android?
    setOnItemClickListener not responding for Custom ListView
  • Android Camera Preview Rotation
  • android-spinnerwheel - Individual tab drawable
  • Jacoco Code Coverage in android studio
  • Not able to get the TelephonyManager.CALL_STATE_RINGING
  • How to grant MODIFY_PHONE_STATE permission for apps ran on Gingerbread
  • How to use Fragments in Android
  • 2 Solutions collect form web for “How to properly add custom view to the toolbar?”

    I believe the toolbar behaves more or less like a LinearLayout, even when it doesn’t extend it.

    If I’m right, you wouldn’t be able to use “two rows” like you intend.

    Maybe you can take that EditView out of the toolbar, or alternatively, use ActionBar (With the ‘X’ icon and the actions) and below a toolbar with the EditText.

    You can add a custom layout with EditText below the Toolbar, with the same background color.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.