Creating custom toolbar, action bar

3

I'm creating a separate toolbar to facilitate development I'm trying to make a simple toolbar but I can not do it.

How I want to do: link

My code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFF">

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_marginLeft="3dp"
    android:layout_marginRight="3dp"
    android:layout_marginTop="20dp"
    android:background="@color/servisale_blue" />


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

How it works: link

    
asked by anonymous 15.10.2016 / 22:06

1 answer

3

By default there is a space in the Toolbar of 16dp , so it is necessary to use the contentInsetStart method, setting it to 0dp . Read more about Metrics & keylines in documentation of Material Design. See the specification image:

IwasabletoredoyourToolbar,seebelow:

<?xmlversion="1.0" encoding="utf-8"?>
       <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#fff"
            app:contentInsetEnd="0dp"
            app:contentInsetLeft="0dp"
            app:contentInsetRight="0dp"
            app:contentInsetStart="0dp">

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="56dp"
                android:gravity="center"
                android:orientation="vertical">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="horizontal"
                    android:gravity="center"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="8dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Login"
                        android:background="#639DAF"
                        android:textColor="#fff"
                        android:padding="6dp"
                        android:layout_centerVertical="true"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentStart="true" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="HOME"
                        android:layout_centerVertical="true"
                        android:textColor="#639DAF"
                        android:layout_centerHorizontal="true" />

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@android:drawable/ic_dialog_dialer"
                        android:layout_centerVertical="true"
                        android:layout_alignParentRight="true"
                        android:layout_alignParentEnd="true" />

                </RelativeLayout>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    android:layout_marginRight="10dp"
                    android:layout_marginLeft="10dp"
                    android:background="#639DAF" />

            </RelativeLayout>
        </android.support.v7.widget.Toolbar>
    
15.10.2016 / 22:46