我的应用程序目前是使用单一活动方法实现的(使用带有一个主活动和几个片段的导航架构组件)。我目前正在使用带抽屉的工具栏。
我的应用目前看起来是这样的:
然而,在现代的谷歌应用程序(谷歌照片,gmail等)中,谷歌已经实现了一种新的导航方式,使用搜索字段并在其中实现了一个抽屉,如下所示:
我想用搜索栏和抽屉菜单替换这个工具栏,就像Google应用程序一样。
有没有人能帮我写一些代码来实现这一点?
我的主要活动如下:
代码语言:javascript运行复制
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> android:id="@+id/Drawer_Main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".ui.main.main.MainActivity"> android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> android:id="@+id/Toolbar_Main" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary"> android:id="@+id/Toolbar_Title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/app_name" style="@style/Locky.Toolbar.TitleText" /> android:id="@+id/Nested_Scroll" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="?attr/actionBarSize" app:layout_behavior="@string/appbar_scrolling_view_behavior"> android:id="@+id/Navigation_Host" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="match_parent" app:defaultNavHost="true" app:navGraph="@navigation/navigation_drawer_main" /> android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:orientation="vertical"> android:id="@+id/FAB_Account" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_marginEnd="16dp" android:layout_marginStart="16dp" android:visibility="invisible" app:srcCompat="@drawable/ic_account" style="@style/Locky.FloatingActionButton.Mini" /> android:id="@+id/FAB_Card" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_marginEnd="16dp" android:layout_marginStart="16dp" android:visibility="invisible" app:srcCompat="@drawable/ic_credit_card" style="@style/Locky.FloatingActionButton.Mini" /> android:id="@+id/FAB_Add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="@dimen/fab_margin" android:layout_marginEnd="@dimen/fab_margin" android:layout_marginBottom="@dimen/fab_margin" app:srcCompat="@drawable/ic_add" style="@style/Locky.FloatingActionButton.Normal"/> android:id="@+id/Navigation_View" android:layout_width="280dp" android:layout_height="match_parent" android:layout_gravity="start" android:clipToPadding="false" app:itemTextAppearance="@style/Locky.TextAppearance.Drawer.Item" app:menu="@menu/menu_drawer_main" app:headerLayout="@layout/drawer_header" style="@style/Locky.Widget.Custom.NavigationView" />