我正在使用具有擴展高度(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