我正在使用具有扩展高度(56dp + 80dp)的工具栏,并且想要将EditText添加到工具栏的底部。我的问题是,EditText上不低于图片本身扩展到右边,如:如何正确添加自定义视图到工具栏?
代码如下所示:
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" />
将布局添加到工具栏:
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);
您是否曾经找到过解决方案? – DDukesterman 2015-02-02 19:05:16
其实我在答案中就像descibed - 在工具栏下面添加了自定义布局。恐怕现在没有其他解决方案了。 – miqqo 2015-02-07 19:12:35