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:
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);
You can make other changes like font, size, color, etc in custom_toolbar. xml file. If you want to change the text of custom toolbar, you can do in this way: ....
This is going to be in res/menu/main_menu . Right click the res folder and choose New > Android Resource File. Type main_menu for the File name. Choose Menu for the Resource type.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With