Creating custom toolbar?

自作多情 提交于 2019-12-12 11:26:59

问题


Please help me to create a toolbar like this home page design:
.

The toolbar has 3 buttons on top (3 imagebuttons) and 2 buttons below, searchbox (imagebutton) and lens (imagebutton)

I've placed 3 buttons on top but I couldn't add search box and lens buttons on correct position

I'm using a navigation drawer activity. The activity name is 'home'

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
    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"
    tools:context="com.example.cortana.shopv3.HomeActivity">


        <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            android:weightSum="1">

                <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                app:srcCompat="@android:drawable/ic_menu_sort_by_size"
                android:layout_marginLeft="100sp"
                android:background="@null"
                android:adjustViewBounds="true"
                android:cropToPadding="true" />

                <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                app:srcCompat="@android:drawable/btn_plus"
                android:layout_marginLeft="15sp"
                android:background="@null"
                android:adjustViewBounds="true"
                android:cropToPadding="true" />

            <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:srcCompat="@android:drawable/ic_menu_save"
            android:id="@+id/savebtn"
            android:background="@drawable/refreshgreen"
            android:adjustViewBounds="true"
            android:layout_marginLeft="15sp"
            android:layout_alignParentTop="true"
            android:layout_marginBottom="15sp"
            android:cropToPadding="true" />


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

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

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

回答1:


try this make your toolbar like this

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginLeft="100sp"
                android:adjustViewBounds="true"
                android:background="@null"
                android:cropToPadding="true"
                app:srcCompat="@android:drawable/ic_menu_sort_by_size" />

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginLeft="15sp"
                android:adjustViewBounds="true"
                android:background="@null"
                android:cropToPadding="true"
                app:srcCompat="@android:drawable/btn_plus" />

            <ImageButton
                android:id="@+id/savebtn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_marginBottom="15sp"
                android:layout_marginLeft="15sp"
                android:adjustViewBounds="true"
                android:background="@drawable/ic_down"
                android:cropToPadding="true"
                app:srcCompat="@android:drawable/ic_menu_save" />
        </LinearLayout>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</android.support.v7.widget.Toolbar>


来源:https://stackoverflow.com/questions/45265185/creating-custom-toolbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!