【问题标题】:Android Toolbar isn't showing upAndroid 工具栏未显示
【发布时间】:2021-04-13 08:57:55
【问题描述】:

我在我的应用中使用抽屉、底部导航栏和工具栏。

所以我通过在抽屉布局中包含布局来放置我的工具栏。

抽屉通过滑动可以正常工作,但工具栏没有显示。

我认为工具栏被片段覆盖,但我不知道为什么......

我已经在 MainActivity 中设置了SupportActionBar。

有什么问题??

toolbar_layout.xml

<?xml version="1.0" encoding="utf-8"?>
 <androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="56dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@android:color/transparent"
android:id="@+id/toolbar"
>

<Button
    android:layout_width="24dp"
    android:layout_height="24dp"
    android:background="@drawable/ic_menu"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    />

<Button
    android:layout_width="24dp"
    android:layout_height="24dp"
    android:background="@drawable/ic_search"
    android:layout_marginEnd="16dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    />
  </androidx.appcompat.widget.Toolbar>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:fitsSystemWindows="true"
>

<androidx.constraintlayout.widget.ConstraintLayout
    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">

    <include
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/toolbar_layout"
        />

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@id/navigationView"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0">

    </FrameLayout>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navigationView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/gray7"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:itemBackground="@color/gray7"
        app:labelVisibilityMode="labeled"
        android:theme="@style/Widget.BottomNavigationView"
        app:itemIconTint="@drawable/menu_selector_color"
        app:itemTextColor="@drawable/menu_selector_color"
        app:menu="@menu/bottom_navigationbar" />
</androidx.constraintlayout.widget.ConstraintLayout>

<com.google.android.material.navigation.NavigationView
    android:id="@+id/nvDrawer"
    android:layout_width="304dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    >
    <include layout="@layout/drawer_layout"/>

</com.google.android.material.navigation.NavigationView>


</androidx.drawerlayout.widget.DrawerLayout>

【问题讨论】:

    标签: android navigation-drawer toolbar


    【解决方案1】:

    您正在从父视图的顶部设置 FrameLayout 容器

    改变这个

    app:layout_constraintTop_toTopOf="parent"
    

    app:layout_constraintTop_toBottomOf="@+id/toolbar"
    

    【讨论】:

      猜你喜欢
      • 2016-08-28
      • 1970-01-01
      • 1970-01-01
      • 2015-02-04
      • 2019-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多