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

标签 android xml android-studio android-toolbar

我尝试了很多。但没有任何效果我正在使用 coodinatorlayout。我还使用了 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>

但我只有这个.. but I got this only.. 我想要底部的工具栏.. 我在 content main 中尝试了它。然后它起作用了,但是 bar 的宽度不覆盖父宽度。但是我不需要在 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 - 如何将工具栏放在应用程序的底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35885974/

相关文章:

android - 如何为srcs :[] in android. bp文件添加相对路径

xml - Excel XML : Formatting inline text

xmllint:非根 xml 元素上的 xmlns?

android - 运行 Android Emulator 时出现错误 CLOCK_WATCHDOG_TIMEOUT

java - 如何将 Firebase 与 Glide ('using' 方法集成)

android - OnFocusChangeListener 监听背景点击

Android - 在电话上接收联系人更改

php - 使用 XPath 和 PHP 删除 XML 中的节点

android - 如何在 Android Studio 中忽略库的 minSdkVersion?

java - Libgdx - 使用TexturePacker时出现错误