Kar
Kar

Reputation: 6345

How to align with the title of the Toolbar?

I'm trying to align a row with an icon and a text field with the navigation button and title of the toolbar, respectively.

According to the design specification, the title is 72dp away from the left edge:

enter image description here

If I use 72dp, like below, I don't get an alignment

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <ImageView android:layout_width="56dp"
               android:layout_height="56dp"
               android:padding="16dp"
               android:id="@+id/icon"/>

    <EditText android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:singleLine="true"
              android:id="@+id/text"
              android:layout_marginLeft="16dp"
              android:layout_marginRight="16dp"/>
</merge>

enter image description here

Does anyone know what might be wrong?

Thanks

UPDATE Customised the toolbar as per @Mike's advice:

enter image description here

enter image description here

Upvotes: 3

Views: 634

Answers (1)

Mike
Mike

Reputation: 4570

First thing to mention is that the title on the screenshot you pasted is not at 72dp from left but it rather looks like 56dp.

Basically the problem is that Google writes something in their documentation but when it comes to implement things they do it differently.

Here is a really great post from Lucas Urbas explaining in detail all the Toolbar misunderstandings on Android.

Upvotes: 1

Related Questions