本篇博客是在网上学习快速封装一个ToolBar的基类的灵感,作了一定程度的衍生。
第一步:创建一个BaseActivity并在其布局文件中设定标题栏的样式,FrameLayout是用于装载子类Activity的布局。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/topbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorPrimary">
<ImageButton
android:scaleX="0.5"
android:scaleY="0.5"
android:id="@+id/left_btn"
android:layout_width="50dp"
android:layout_height="50dp"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:layout_centerInParent