我正在使用具有扩展高度(56dp + 80dp)的工具栏,并且想要将 EditText 添加到工具栏的底部。我遇到的问题是 EditText 不会将自身扩展到右边缘,如下图所示:
代码如下所示:
工具栏_编辑_文本.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);
我相信工具栏的行为或多或少类似于 LinearLayout,即使它没有扩展它。
如果我是对的,您将无法像您想要的那样使用“两行”。
也许您可以将该 EditView 从工具栏中取出,或者使用ActionBar
(带有“X”图标和操作),工具栏下方带有 EditText。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)