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

  • Interface Builder(User Interface Designer) for Android
  • Facebook key hash does not match any stored key hashes
  • Tabs Coming above Action bar when inflating custom layout
  • Creating default style with custom attributes
  • How to display both normal and split ActionBar?
  • Updating progress dialog in Activity from AsyncTask
  • The code looks like below:


    <?xml version="1.0" encoding="utf-8"?>
    <EditText xmlns:android=""
        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);

  • SharedPreferences from different activity
  • Passing a JavaScript object using addJavascriptInterface() on Android
  • How do I get the ScreenSize programmatically in android
  • Google Glass ADB devices doesn't find. OMAP4430 driver not installed (can't find it!)
  • Unmarshalling XML files into Java objects in Android?
  • How to set images for ScrollView instead-of fading edges?
  • 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.