這段時間在幫別人寫一個App,為了加快進度,就引入了一些開源庫,其中一個是TitleBar,Github上的地址是
https://github.com/loperSeven/TitleBar , slogan是滿足各種日常使用的標題欄,不要讓你的時間浪費在寫標題欄上。聽起來很不錯。
在build.gradle里面引入遠程依賴
implementation 'com.github.loperSeven:TitleBar:1.0.3'
在activity或者是fragment的xml布局里面只需要使用TitleBar就可以了,如
<
com.loper7.layout.TitleBar
android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="50dp" tl:tBackgroundColor="@color/colorPrimary" tl:tTitleText="活動" tl:tTitleTextColor="@color/black" tl:tCenterTitle="true" tl:tTitleTextBold="true" tl:tTitleTextSize="18sp" />
上面基本上默認的配置,如果需要設置左邊的返回箭頭,可以使用tBackImage來設置箭頭圖標。
其他的屬性用法,可以參考文檔或者是源碼,比較簡單。
這樣后續就不用重復的寫titleBar了。