Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] Must Toolbar be wrapped with AppBarLayout in Android Studio?

Posted on November 14, 2022

Solution 1 :

You cant have scrolling effects in Toolbar. So AppBarLayout is used, see below images, you can achieve by using only AppBarLayout.

enter image description here enter image description here

Solution 2 :

Toolbar is just an usual View and it may be placed anywhere you want, even few in one XML. AppBarLayout is used to wrap Toolbar (or other View, e.g. TabLayout) and add some scroll-behavior change possibilities, when placed above some scrolling container like ScrollView or RecyclerView (you probably want to use Nested versions then)

check out nested classes listed in summary in on top of AppBarLayout doc – all related to scrolling (e.g. OnOffsetChangedListener or ScrollingViewBehavior)

Problem :

The Code A is from the project architecture samples, the toolbar is wrapped with AppBarLayout.

I remove AppBarLayout and get Code B, and Code B works well just like Code A.

Must Toolbar be wrapped with AppBarLayout in Android Studio?

Code A (tasks_act.xml)

<androidx.drawerlayout.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"
    tools_context=".tasks.TasksActivity"
    tools_openDrawer="start">

    <LinearLayout
        android_layout_width="match_parent"
        android_layout_height="match_parent"
        android_orientation="vertical">

        <com.google.android.material.appbar.AppBarLayout
            android_layout_width="match_parent"
            android_layout_height="wrap_content">

            <androidx.appcompat.widget.Toolbar
                android_id="@+id/toolbar"
                android_layout_width="match_parent"
                android_layout_height="wrap_content"
                android_minHeight="?attr/actionBarSize"
                android_theme="@style/Toolbar"
                app_popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </com.google.android.material.appbar.AppBarLayout>

        <fragment
            android_id="@+id/nav_host_fragment"
            android_name="androidx.navigation.fragment.NavHostFragment"
            android_layout_width="match_parent"
            android_layout_height="match_parent"

            app_defaultNavHost="true"
            app_navGraph="@navigation/nav_graph" />

    </LinearLayout>

    <!-- Navigation Drawer -->
    <com.google.android.material.navigation.NavigationView
        android_id="@+id/nav_view"
        android_layout_width="wrap_content"
        android_layout_height="match_parent"
        android_layout_gravity="start"
        android_fitsSystemWindows="true"
        app_headerLayout="@layout/nav_header"
        app_itemIconTint="@drawable/drawer_item_color"
        app_itemTextColor="@drawable/drawer_item_color"
        app_menu="@menu/drawer_actions" />

</androidx.drawerlayout.widget.DrawerLayout>

Code B (tasks_act.xml)

<androidx.drawerlayout.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"
    tools_context=".tasks.TasksActivity"
    tools_openDrawer="start">

    <LinearLayout
        android_layout_width="match_parent"
        android_layout_height="match_parent"
        android_orientation="vertical">

       <androidx.appcompat.widget.Toolbar
           android_id="@+id/toolbar"
           android_layout_width="match_parent"
           android_layout_height="wrap_content"
           android_minHeight="?attr/actionBarSize"
           android_theme="@style/Toolbar"
           app_popupTheme="@style/ThemeOverlay.AppCompat.Light" />
     

        <fragment
            android_id="@+id/nav_host_fragment"
            android_name="androidx.navigation.fragment.NavHostFragment"
            android_layout_width="match_parent"
            android_layout_height="match_parent"

            app_defaultNavHost="true"
            app_navGraph="@navigation/nav_graph" />

    </LinearLayout>

    <!-- Navigation Drawer -->
    <com.google.android.material.navigation.NavigationView
        android_id="@+id/nav_view"
        android_layout_width="wrap_content"
        android_layout_height="match_parent"
        android_layout_gravity="start"
        android_fitsSystemWindows="true"
        app_headerLayout="@layout/nav_header"
        app_itemIconTint="@drawable/drawer_item_color"
        app_itemTextColor="@drawable/drawer_item_color"
        app_menu="@menu/drawer_actions" />

</androidx.drawerlayout.widget.DrawerLayout>
READ  [ANSWERED] How to hide warning "The console output contains very long lines (...)" when building apk in Android Studio
Powered by Inline Related Posts

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress