【发布时间】:2014-10-26 13:40:14
【问题描述】:
我正在使用扩展高度 (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);
【问题讨论】:
-
你找到解决方案了吗?
-
实际上我在答案中做了描述 - 确实在工具栏下方添加了自定义布局。恐怕目前没有其他解决方案。