Creating custom Toolbar, action bar

Asked

Viewed 1,313 times

3

Guys I’m creating a separate Toolbar to facilitate the development I’m looking to make a very simple Toolbar but I can’t

how I want to do: http://prntscr.com/cuipex

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 does it look: http://prntscr.com/cuitno

  • 1

    To make a custom Toolbar the path is the same, but you have to set the properties correctly inside your Toolbar.

1 answer

3


By default there is a spacing in the Toolbar of 16dp, then it is necessary to use the method contentInsetStart defining it as 0dp. Read more about Metrics & keylines in documentation Material Design. See the image of the specifications:

inserir a descrição da imagem aqui

I managed to redo your Toolbar, see below:

       <?xml version="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>
  • Whoops that’s right there I’ll just adapatar here for me to use in button form can answer another quick thing to create this login knob it pays to use imageButton or create a Shape or some other way?

  • Imagebutton is in case you want to put some image, this way I did customizing Textview already works perfectly, but in my opinion, you can do using Button same.

  • Just reminding you there’s a way setOnClickListener in a Textview too. Hugs and good luck.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.