Android 如何在工具栏下方添加视图?

Android 如何在工具栏下方添加视图?,android,android-custom-view,android-toolbar,Android,Android Custom View,Android Toolbar,是否有一种简单的方法可以在不影响工具栏当前外观的情况下在工具栏下方添加视图?我只想在工具栏文本的正下方添加一个额外的视图。请注意,工具栏有阴影,只需在工具栏小部件下方添加视图将无法实现我想要的效果。使用此代码即可 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_

是否有一种简单的方法可以在不影响工具栏当前外观的情况下在工具栏下方添加视图?我只想在工具栏文本的正下方添加一个额外的视图。请注意,工具栏有阴影,只需在工具栏小部件下方添加视图将无法实现我想要的效果。

使用此代码即可

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:orientation="vertical">

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/app_color"
    android:titleTextAppearance="@android:color/white"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- **** Place Your Content Here **** -->


    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="My Content"/>

    <!-- **** This is your view that appears below toolbar **** -->
    <View
        android:layout_width="match_parent"
        android:layout_height="5dp"
        android:background="@drawable/toolbar_dropshadow" />
</FrameLayout></LinearLayout>


//在此处添加组件

在上面的帖子中,对我有用的是将工具栏的布局更改为线性布局


使用框架布局时,视图位于工具栏下方。

如果使用的是RelativeLayout,请使用:

<android.support.v7.widget.Toolbar
mlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_tool_bar"
android:layout_width="fill_parent"
android:layout_height="@dimen/actionbar_height"
android:gravity="center">

<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

//Add your components here, ie.:
<MyView android:id="@+id/black_box"
android:layout_below="@id/my_toolbar" //relativity left or right available too
android:layout_width="match_parent"
etc.etc./>
</RelativeLayout>

</android.support.v7.widget.Toolbar>`

//在此处添加您的组件,即:
`

我不确定您的工具栏为什么在布局范围之上,但请尝试并让我们知道。

在您的
工具栏中添加
android:layout\u height=“?attr/actionBarSize”
,如:

 <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        android:titleTextColor="#ffffff"
                        android:background="#ECA539"
                        app:layout_collapseMode="pin"
                        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

@普拉奇,我还没有。。我只使用默认工具栏,只想知道如何在标题文本视图下方添加视图,就像在
相对布局
线性布局
@Prachi中添加组件一样,通过这样做,工具栏将水平添加视图(在标题和菜单按钮之间)没有垂直打印,它仍然出现在标题和菜单按钮之间Post your xml and Screenshot中的黑色区域是我要添加的视图
<android.support.v7.widget.Toolbar
mlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_tool_bar"
android:layout_width="fill_parent"
android:layout_height="@dimen/actionbar_height"
android:gravity="center">

<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

//Add your components here, ie.:
<MyView android:id="@+id/black_box"
android:layout_below="@id/my_toolbar" //relativity left or right available too
android:layout_width="match_parent"
etc.etc./>
</RelativeLayout>

</android.support.v7.widget.Toolbar>`
 <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        android:titleTextColor="#ffffff"
                        android:background="#ECA539"
                        app:layout_collapseMode="pin"
                        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<RelativeLayout

                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                android:layout_width="match_parent"
                android:layout_marginTop="?attr/actionBarSize"
                android:layout_height="wrap_content">