Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toolbar title disappears when adding views

I just realized that when I add views to the Toolbar in the xml file, the title disappears.

e.g.

<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>

Without the views the title exists, but when adding my views it disappears.

Example image:

enter image description here

![enter image description here][1]

Any idea how to solve this problem?

Thanks in advance

like image 443
user2410644 Avatar asked May 25 '15 17:05

user2410644


1 Answers

If you want to show your Title with the EditText you have to Add a TextView for that and give TextAppearance "@style/TextAppearance.AppCompat.Title"

<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">

          <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:textAppearance="@style/TextAppearance.AppCompat.Title"
             android:text="@string/title"
             android:textColor="@color/white" />

            <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>
like image 51
Ankii Rawat Avatar answered Oct 22 '22 10:10

Ankii Rawat