【问题标题】:Creating custom toolbar?创建自定义工具栏?
【发布时间】:2017-07-23 12:37:59
【问题描述】:

请帮我创建一个类似这个主页设计的工具栏:
.

工具栏顶部有 3 个按钮(3 个图像按钮)和 下面2个按钮,搜索框(imagebutton)和镜头(imagebutton)

我在顶部放置了 3 个按钮,但我无法在正确的位置添加搜索框和镜头按钮

我正在使用导航抽屉活动。活动名称是“家”

<?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>

【问题讨论】:

    标签: android android-layout toolbar android-toolbar


    【解决方案1】:

    试试这个让你的toolbar 像这样

        <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-25
      • 2017-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-20
      相关资源
      最近更新 更多