How to customize a Toolbar on android?

Asked

Viewed 1,470 times

3

inserir a descrição da imagem aqui

How do I add more buttons to my Toolbar?

  • There in XML you add more items like Buttons. Post your layout(view) here to implement.

1 answer

1

I got it so see if it’s what you want.

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay">

        <Spinner
            android:layout_gravity="left"
            android:id="@+id/spinnerBar"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />

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

</android.support.design.widget.AppBarLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">


</LinearLayout>

  • 1

    He doesn’t want a spinner, he needs more buttons on each other

  • The concept is the same, just replace Spinner with an image view.

  • It is not there that one modifies the contents of a Toolbar, vc uses a menu XML file.

  • 2

    Okay, but if he wants to add a button to the left of Toolbar he won’t be able to do it with just the XML menu, take a look at the link to see if it’s clear. http://stackoverflow.com/a/33277286/5140172

  • Your answer would be appreciated if you added a small explanation.

  • Thanks, @ramaral I’m still new here and I don’t know how to explain I’ll try to improve :)

  • It would suffice to mention that Toolbar inherits from Viewgroup and that it is therefore possible to add any kind of view to him.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.