Gustavo Serna Gustavo Serna - 3 months ago 17
Android Question

Android toolbar not sizing correctly

I have an android toolbar and inside the toolbar I have an editText, and the editText is doing a margin which I dont want.

Here is a picture:

http://imageshack.com/a/img923/3306/Njhv61.png

Here is the toolbar code:

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar_top"
android:background="@drawable/background_toolbar_top"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/buscador"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="10dp"
android:textColor="#666"
android:background="#ccc"
android:textColorHint="#cccc"
android:hint="Buscar"/>


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


Background of the toolbar:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item>
<shape android:shape="rectangle">
<solid android:color="#333"></solid>
</shape>
</item>

<item android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#fff"></solid>
</shape>
</item>

</layer-list>

Answer

Hope this can help:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar_top"
    android:background="@drawable/background_toolbar_top"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp">

    <EditText
        android:id="@+id/buscador"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:textSize="10dp"
        android:textColor="#666"
        android:background="#ccc"
        android:textColorHint="#cccc"
        android:hint="Buscar"/>

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

And you can check this for more information about the marginLeft in Toolbar.