添加视图时,工具栏标题会消失

use*_*644 5 android android-layout android-toolbar

我刚刚意识到,当我在xml文件中向工具栏添加视图时,标题会消失.

例如

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/activity_taskeditor_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:elevation="8dp"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <EditText
                android:id="@+id/activity_taskeditor_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/title"
                android:layout_marginLeft="16dp"
                android:layout_marginRight="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="16dp"
                android:textSize="22sp"/>

        </LinearLayout>

    </android.support.v7.widget.Toolbar>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

没有视图标题存在,但在添加我的视图时它会消失.

示例图片:

在此输入图像描述

![enter image description here][1]
Run Code Online (Sandbox Code Playgroud)

知道如何解决这个问题吗?

提前致谢

Joa*_*huk 0

工具栏不是容器,因此您应该修改代码以使其看起来像这样:

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

    <android.support.v7.widget.Toolbar
        android:id="@+id/activity_taskeditor_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:elevation="8dp"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary">

    <EditText
        android:id="@+id/activity_taskeditor_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:hint="JOA"
        android:textSize="22sp" />

    //OTHER UI ELEMENTS HERE

    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)