Android 设计工具栏和使用浮动动作按钮

Android 设计工具栏和使用浮动动作按钮,android,android-animation,material-design,android-toolbar,floating-action-button,Android,Android Animation,Material Design,Android Toolbar,Floating Action Button,虽然互联网上或多或少有一些关于扩展的工具栏如何工作以及如何向其添加不同的视图的信息,但我想为我和所有想在应用程序中实现扩展的工具栏的人提供一份分步指南(具体来说,如何将视图添加到工具栏,不同视图和工具栏之间的边距应该使用什么度量,等等 如果可能的话,我还想实现一些材质设计动画,因为我在Android中看不到任何此类或内置方法。是一个关于如何使用全新工具栏的不错教程 将工具栏集成到活动中后,您可以像往常一样添加菜单项。(通过onCreateOptionMenu()和xxx_menu.xml) 还有

虽然互联网上或多或少有一些关于扩展的
工具栏
如何工作以及如何向其添加不同的
视图
的信息,但我想为我和所有想在应用程序中实现扩展的
工具栏
的人提供一份分步指南
(具体来说,如何将视图添加到
工具栏,不同
视图
工具栏
之间的边距应该使用什么度量,等等

如果可能的话,我还想实现一些材质设计动画,因为我在Android中看不到任何此类或内置方法。

是一个关于如何使用全新工具栏的不错教程

将工具栏集成到活动中后,您可以像往常一样添加菜单项。(通过onCreateOptionMenu()和xxx_menu.xml)

还有…是关于FAB aka浮动操作按钮的教程。


更新: 在Google I/O 2015之后,您可以使用来实现材料设计视图,如浮动操作按钮(FAB)。仍将使用v7支持库创建
工具栏,如下所示


设计
工具栏
: 通过查看,我成功地设置了扩展的
工具栏
如何使用正确的规格和测量值

在我的例子中,我使用
片段
s来更改主要内容(扩展的
工具栏
中的
视图也会不同),因此我有一个活动布局文件,其他片段有不同的布局文件。我主要活动的布局是:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include android:id="@+id/main_toolbar" layout="@layout/toolbar" />

    <FrameLayout
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/main_toolbar" />
</RelativeLayout>
以及
框架布局中的内容(在主活动的布局中)将在Java中更改。我的一个片段需要两个
微调器,我想将它们嵌入扩展的
工具栏
工具栏可以方便地用作
视图组
,因此我为我的一个片段创建并使用以下布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v7.widget.Toolbar
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/extended_toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:contentInsetStart="72dp"
        app:contentInsetEnd="16dp"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="bottom|center_horizontal"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >

            <include layout="@layout/toolbar_space_margin" />

            <Spinner
                android:id="@+id/spinner_one"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

            <Spinner
                android:id="@+id/spinner_two
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"/>

            <include layout="@layout/toolbar_space_margin" />
        </LinearLayout>
    </android.support.v7.widget.Toolbar>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/extended_toolbar" >

        <!-- The main content of that activity layout -->

    </ScrollView>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<Space
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="16dp" />
使用浮动操作按钮: 至于使用浮动动作按钮,我找到了各种教程和一个关于这一点的例子,所以我使用了它们。我应该对问题的这一部分进行更好的研究


我希望在设计方面遇到这个问题的其他人会发现这个答案很有用。

谢谢,但是两个教程链接是相同的。你能更新教程中关于使用
工具栏以及扩展它的链接吗?再次感谢。但是我想知道如何更具体地实现扩展的工具栏工具栏,包含子视图以及如何定位它们。
<?xml version="1.0" encoding="utf-8"?>
<Space
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="16dp" />