簡體   English   中英

Android:導航抽屜中每個片段的不同工具欄

[英]Android: different toolbar for each fragment in navigation drawer

我正在制作一個 Android 應用程序,它有一個活動和多個片段以及一個 NavigationDrawer。 現在所有片段都有相同的工具欄,但我希望每個片段都有不同的工具欄,但我找不到最好的方法。 我閱讀了一些教程,但每個人都以不同的方式制作它,我想做最好的解決方案有人能解釋一下最好的方法嗎(不需要編寫代碼,只有想法)

我的意見是使用 Toolbar 作為每個片段布局的一部分。 這樣你就有可能按照你需要的方式定制它。 如果每個屏幕都有共同點,您可以制作自定義工具欄並將其包含在每個布局中。

例子:

<LinearLayout
        android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background_gray"
        android:orientation="vertical">

        <include layout="@layout/back_button_toolbar" />
 
        <!-- Your layout here... -->
</LinearLayout>

並且后退按鈕工具欄可以根據需要進行自定義。 像這樣的東西:

<androidx.appcompat.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/back_toolbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/top_bar_height"
    android:background="@color/whitelabel_topbar_color"
    app:navigationIcon="@drawable/ic_navigate_back">

    <TextView
        android:id="@+id/toolbar_title"
        style="@style/ToolbarTitle"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:gravity="center" />

</androidx.appcompat.widget.Toolbar>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM