如何将工具栏放在应用程序的底部?

How to put toolbar on bottom side of the app?

我试了很多。但没有用 我正在使用 coodinatorlayout.I 也使用 android:layout_alignParentBottom="true" 但效果不佳 我的应用 bar_xml 是

<?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.ezybzy.ezybzy.subcategory">

    <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.support.v7.widget.Toolbar
            android:id="@+id/toolbar_bottom"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:background="?attr/colorPrimary"
            android:layout_alignParentBottom="true"
            android:minHeight="?attr/actionBarSize"
            />
    </android.support.design.widget.AppBarLayout>

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

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

和activity主要xml是

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_categories"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:menu="@menu/activity_main2_drawer"
        android:layout_marginTop="?attr/actionBarSize"/>

</android.support.v4.widget.DrawerLayout>

但我只有这个.. 我想要底部的工具栏.. 我在 content main 中尝试了它。然后它起作用了,但是 bar 的宽度没有覆盖父 width.But 我不需要在 content main 中使用 padding 0dp

我的内容xml是

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.ezybzy.ezybzy.subcategory"
    tools:showIn="@layout/app_bar_subcategory"
    android:background="#ffffff">


</RelativeLayout>

我对你的问题有一个建议。我添加一个 AppBarLayout 如下:

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

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

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

注意:使用 layout_gravity="bottom|end" 设置此 AppBarLayout。 希望能帮到你。

Android 设计支持库帮助我实现了这一目标

做同样的事情 BottomNavigationView 参考

  1. https://segunfamisa.com/posts/bottom-navigation-view-android

  2. https://developer.android.com/reference/android/support/design/widget/BottomNavigationView.html