如何将工具栏放在应用程序的底部? [英] How to put toolbar on bottom side of the app?

查看:94
本文介绍了如何将工具栏放在应用程序的底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了很多.但我使用coodinatorlayout却没有任何效果.我也使用了android:layout_alignParentBottom="true" 但是效果不好 我的应用程序bar_xml是

I tried many. but nothing worked I am using coodinatorlayout.I also used android:layout_alignParentBottom="true" But it is not working well my app bar_xml is

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

但是我只有这个.. 我希望工具栏位于底部. 我在内容主体中尝试过.然后它起作用了,但是条形的宽度不能覆盖父宽度.但是我不需要在内容主体中使用 padding 0dp .

but I got this only.. I want toolbar at bottom.. I tried it in content main .Then its worked but the width of bar does not cover parent width.But I don't need a padding 0dp in content main.

我的内容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,如下所示:

I have a suggetion for your issue. I add an AppBarLayout as below:

<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. 希望能对您有所帮助.

notice: set this AppBarLayout with layout_gravity="bottom|end". Hope to help you.

这篇关于如何将工具栏放在应用程序的底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆