ToolBar不做过多的介绍,直接写如何使用。
1.在XML布局文件中加入ToolBar控件,用V7包里面的控件。否则只支持5.0以上的(在其它文章中看到的,没有去验证)。
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_doing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/colorPrimary">
</android.support.v7.widget.Toolbar>
2.(1)如果没有隐藏掉标题栏(ActionBar),就需要使用一个方法替换掉ActionBar,加入ToolBar。
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_doing);
setSupportActionBar(toolbar);
这样就能达到想要的效果。
注意:
如果使用了setSupportActionBar()方法