Definition location of android toolbar

Asked 2 years ago, Updated 2 years ago, 92 views

When you use multiple fragments for one activity, you sometimes want to use different toolbars for each fragment. Only one toolbar is defined in activity, and how to customize and write in each fragment, and the toolbar is defined for each fragment ((AppcompatActivity)context).Which is common: setSupportActionbar (toolbar);? Or is there any other way?

android toolbar fragment

2022-09-22 11:39

1 Answers

Well, there's a way to write fragments like that. In my case, I just make a toolbar in Activity Sometimes the contents of the toolbar should be different, and so on. (Honestly, I didn't know how to do it differently.)<<) much..

So I did this

    <android.support.v7.widget.Toolbar
        android:background="@color/colorPrimary"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_gravity="center"
            android:textStyle="bold"
            android:text="Train Inquiry"
            android:textSize="28dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <ImageButton
            android:layout_gravity="left"
            android:background="@drawable/ic_menu_white_24dp"
            android:layout_width="48dp"
            android:layout_height="48dp"/>

    </android.support.v7.widget.Toolbar>

If you do this, it looks like the picture below

As you can see, the toolbar is created... I believe that it will be possible to modify the contents to some extent, so then...<


2022-09-22 11:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.