android - Should we replace Action Bar by ToolBar? -
i have been using toolbar
since added support v7 library. , think used well. there point can't understand. why google create such widget? mean can toolbar
can using actionbar
. why have use toolbar
? advantages of toolbar
on actionbar
if any? necessary replace actionbar
toolbar
?
any tips appreciated. , in advance.
ps: found toolbar
decandant of viewgroup
. so, how use toolbar
layout
? post codes of that?
yes should replace actionbar new toolbar
reasons
1) looks modern , follows new material design
2) unlike action bar , toolbar not part of window decor.you defines , place other widget...therefor have freedom place anywhere in parent layout.
3) have freedom put widget inside toolbar.
4) can define multiple toolbars.
edit
what meant can place other widgets(views) inside toolbar.
create separate layout file toolbar(good reusability).in case file name main_toolbar .
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:segmentedgroup="http://schemas.android.com/apk/res-auto" android:id="@+id/toolbar" android:layout_width="match_parent" app:theme="@style/toolbarcoloredbackarrow" android:layout_height="56dp" android:background="@color/primary_color" > <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textsize="@dimen/drawer_fntsize" android:text="title" android:id="@+id/lbl_title" android:textcolor="@color/title_text_color" android:layout_gravity="center" /> </android.support.v7.widget.toolbar>
then include toolbar in main layout this
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <include android:id="@+id/toolbar" layout="@layout/main_toolbar"/> <framelayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/toolbar" />
as can see in example placed textview inside toolbar