java - 尝试将导航抽屉按钮添加到应用栏
问题描述
我正在关注本教程
我被困在我试图将按钮添加到应用栏的地方。
当我向右滑动时,会出现导航抽屉,这样就可以了。它只是我遇到问题的栏中的按钮,当我将其添加v7.widget.Toolbar
到 FrameLayout 下的 XML 中时,它会破坏布局。
最初在我的 XML 中,我只有一个约束布局,其中一个 Scrollview 作为子项,在其中一个 LinearView(垂直)。
但是我无法理解为什么这不起作用:
<?xml version="1.0" encoding="utf-8"?>
<!-- Use DrawerLayout as root container for activity -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Container for contents of drawer - use NavigationView to make configuration easier -->
<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/drawer_view"
app:headerLayout="@layout/nav_header" />
<!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/seeds_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:background="@drawable/customborder"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"></LinearLayout>
</ScrollView>
</FrameLayout>
当我运行它时,顶部栏似乎超过了整个窗口并且颜色消失并且按钮不可点击,因为LinearLayout
它在它的顶部。我哪里错了?
解决方案
放在NavigationView
下面FrameLayout
。
推荐阅读
- python - 在Python中查找具有一定总数的列
- spring-boot - 使用 Prometheus 监控 SprinBoot 微服务
- c# - IIS Express 与 Fiddler 一起使用,但在远程 API 访问 C# 时返回 500
- python - 基本 gTTS 库使用导致 Python 3.7 中的 RuntimeError
- javascript - 我可以使用什么 RegExp 标志来帮助我在字符串中查找数字?
- ios - 当 Info.plist 功能不存在时,PKPaymentAuthorizationViewController.canMakePayments() 返回 true
- r - 一次从变量中删除一个数据元素(值)并在 R 中执行函数
- python - 如何将字典写入 CSV 文件?
- ios - 一个带有按钮的 ViewController 中的多个音频文件
- r - 如何对由家庭 ID 链接的变量的多行值求和