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

4

我尝试了很多方法,但都没有成功。我正在使用coodinatorlayout布局。我也使用了 android:layout_alignParentBottom="true",但效果并不好。 我的app 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>

活动主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中尝试过。然后它起作用了,但是栏的宽度没有覆盖父宽度。但我不需要在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>

你的 content_subcategory 的 XML 文件在哪里? - Amit Vaghela
但是有些用户友好的应用程序使用底部工具栏,对吧?@Tim Castelijns - Kiran Benny Joseph
2个回答

4

我有一个关于你的问题的建议。我添加了一个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>

注意:请将此AppBarLayout设置为 layout_gravity="bottom|end"。希望能对您有所帮助。


不,当我这样做时,当前的操作栏也会向下移动..我想要两个操作栏..一个在顶部,另一个在底部。 - Kiran Benny Joseph
@KBJ,我的建议是您仍然保留一个具有AppBarLayout layout_gravity="top|start"的工具栏,并添加另一个具有AppBarLayout layout_gravity="bottom|end"的工具栏。 - dolphin

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接