Android 带有编辑文本的自定义工具栏布局
我使用edittext为工具栏创建了自定义布局,但它不适合工具栏。 我需要这样的工具栏 但是得到了这个输出 我需要全文编辑。帮助我实现这一目标 我的XML代码Android 带有编辑文本的自定义工具栏布局,android,toolbar,Android,Toolbar,我使用edittext为工具栏创建了自定义布局,但它不适合工具栏。 我需要这样的工具栏 但是得到了这个输出 我需要全文编辑。帮助我实现这一目标 我的XML代码 我也在谷歌上搜索过,但没能做到这一点 当您使用工具栏时,它会在菜单图标后添加一些空白。所以你必须在工具栏下方添加具有相同背景颜色的搜索视图,如果有任何滚动条,则将其固定,然后在搜索布局下方添加该滚动条。试试这个 <LinearLayout android:layout_width="match_parent"
我也在谷歌上搜索过,但没能做到这一点 当您使用工具栏时,它会在菜单图标后添加一些空白。所以你必须在工具栏下方添加具有相同背景颜色的搜索视图,如果有任何滚动条,则将其固定,然后在搜索布局下方添加该滚动条。试试这个
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/_25sdp"
android:background="?attr/colorPrimary"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:gravity="center"
app:contentInsetStart="0dp"
app:layout_scrollFlags="scroll|enterAlways"
app:navigationIcon="@drawable/icon_toolbar_back"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
app:theme="@style/ThemeOverlay.AppCompat.Dark"
app:titleTextAppearance="@style/ToolbarTextAppearance">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/imgActionLogo"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_gravity="center"
android:src="@drawable/common_google_signin_btn_icon_dark"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="@dimen/_25sdp"
android:background="?attr/colorPrimary">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/_25sdp"
android:layout_marginBottom="@dimen/_5sdp"
android:layout_marginLeft="@dimen/_10sdp"
android:layout_marginRight="@dimen/_10sdp"
android:background="@drawable/toolbar_search_bg"
android:gravity="center"
android:orientation="horizontal"
android:paddingLeft="@dimen/_5sdp"
android:paddingRight="@dimen/_5sdp"
app:layout_scrollFlags="scroll|enterAlways">
<ImageView
android:layout_width="@dimen/_20sdp"
android:layout_height="@dimen/_20sdp"
android:src="@drawable/icon_search" />
<EditText
android:id="@+id/etSearch"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/_5sdp"
android:background="@null"
android:editable="false"
android:hint="Search More Products..."
android:textColorHint="@color/text_medium"
android:textSize="@dimen/_10sdp" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
如果使用app:navigationIcon和/或菜单项,工具栏的内部内容将缩小 您可以省略app:navigationIcon和菜单项,并在工具栏中创建自己的按钮 然后设置
<android.support.v7.widget.Toolbar
...
app:contentInsetRight="0dp"
app:contentInsetLeft="0dp">
...
</android.support.v7.widget.Toolbar>
...
应该给你更多的内容填充控制权目前我使用这个功能,效果很好,但在某些片段中,我需要隐藏操作栏,然后工具栏被隐藏,但搜索栏不被隐藏。是否可能只有工具栏包含所有视图?你可以为包含工具栏和搜索布局的父线性布局提供id,并隐藏父布局只要你需要。
<android.support.v7.widget.Toolbar
...
app:contentInsetRight="0dp"
app:contentInsetLeft="0dp">
...
</android.support.v7.widget.Toolbar>