1

I'm new to Android development and need some help :) I just wanted to add custom buttons to toolbar right.

I saw few solutions with LinearLayouts and etc... But i'm not sure is it right way to do this.

Already checked Material design and found TopBar but don't think this is what i need :p

Example: enter image description here

Thanks!

Sqweelow
  • 187
  • 2
  • 13
  • `I saw few solutions with LinearLayouts and etc... But i'm not sure is it right way to do this.` yes you can use that to achieve custom design – Nongthonbam Tonthoi Feb 05 '19 at 17:03
  • What custom icon? For left one [Follow this](https://stackoverflow.com/questions/27028571/how-to-replace-the-hamburger-icon-used-for-actionbartoggle-on-android-toolbar-wi) and the right icon can a Menu so you just need to learn how to add menu . – ADM Feb 05 '19 at 17:05

1 Answers1

2

Create custom toolbar (toolbar.xml), you can use LinearLayout to house your custom design:

<android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="100dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="right">

                <Button
                    android:id="@+id/button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </LinearLayout>
    </android.support.v7.widget.Toolbar>

Include custom toolbar into your activity.xml:

<include
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   layout="@layout/toolbar" />

To access Button:

Button button = (Button) findViewById(R.id.button);


button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                //Your logic  
            }
        });
Sha-1
  • 187
  • 4
  • 12