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
Thanks!
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
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.