MrDick
MrDick

Reputation: 51

Android Toolbar TextView match_parent getting bigger than screen

I have a Toolbar with a TextView inside with match_parent to center the text but every time I do so it gets bigger than the screen and hides the text.

Here you have a capture of it running

enter image description here

How this looks like in the preview

enter image description here

And finally how I implement it:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="8dp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:theme="@style/ToolBarStyle" >

            <TextView
                android:id="@+id/toolbar_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:text="@string/title_activity_anuncios" />

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

    </android.support.design.widget.AppBarLayout>

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </android.support.constraint.ConstraintLayout>

</LinearLayout>

Upvotes: 1

Views: 218

Answers (2)

Jigar Patel
Jigar Patel

Reputation: 1568

check your theme on style or set activity theme from the manifest

 android:theme="@android:style/Theme.Translucent.NoTitleBar" 

If activity theme is correct then you can check your activity >> onCreate method.

   ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle("Your Title");
    } 

Upvotes: 1

AbhayBohra
AbhayBohra

Reputation: 2117

Put this in your toolbar

app:contentInsetStart="0dp"

Upvotes: 0

Related Questions