Github傳送地址,歡迎Star,Pull及issuejava
已投入公司項目多時,沒有任何毛病,可勝任任何需求,點擊此處下載Demoandroid
想了解實現原理的能夠參考文章:純手工打造一個通用的標題欄TitleBargit
dependencies {
implementation 'com.hjq:titlebar:3.5'
}
複製代碼
<declare-styleable name="TitleBar">
<!-- 標題欄的樣式 -->
<attr name="bar_style">
<enum name="light" value="0x10" />
<enum name="night" value="0x20" />
<enum name="transparent" value="0x30" />
</attr>
<!-- 標題 -->
<attr name="title" format="string" />
<attr name="title_left" format="string"/>
<attr name="title_right" format="string" />
<!-- 圖標 -->
<attr name="icon_left" format="reference" />
<attr name="icon_right" format="reference" />
<!-- 返回按鈕,默認開 -->
<attr name="icon_back" format="boolean" />
<!-- 文字顏色 -->
<attr name="color_title" format="color" />
<attr name="color_right" format="color" />
<attr name="color_left" format="color" />
<!-- 文字大小 -->
<attr name="size_title" format="dimension" />
<attr name="size_right" format="dimension" />
<attr name="size_left" format="dimension" />
<!-- 按鈕背景 -->
<attr name="background_left" format="reference|color" />
<attr name="background_right" format="reference|color" />
<!-- 分割線 -->
<attr name="line_visible" format="boolean" />
<attr name="line_color" format="color" />
<attr name="line_size" format="dimension" />
</declare-styleable>
複製代碼
點我查看完整的Demo示例github
<com.hjq.bar.TitleBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="默認的標題欄" />
複製代碼
mTitleBar.setOnTitleBarListener(new OnTitleBarListener() {
@Override
public void onLeftClick(View v) {
ToastUtils.show("左項View被點擊");
}
@Override
public void onTitleClick(View v) {
ToastUtils.show("中間View被點擊");
}
@Override
public void onRightClick(View v) {
ToastUtils.show("右項View被點擊");
}
});
複製代碼
若是對TitleBar的默認樣式不滿意,能夠在Application初始化樣式,具體可參考TitleBarLightStyle的實現app
public class XXApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
TitleBar.initStyle(new ITitleBarStyle());
}
}
複製代碼
性能最佳:不使用LayoutInflater,而使用代碼建立View的形式框架
體驗最優:TitleBar默認樣式效果已經很是好,可下載Demo測試ide
支持夜間模式:能夠直接引用框架中的TitleBarNightStyle樣式佈局
支持操控子控件:能夠在代碼中獲取TitleBar的子控件進行調用相關的API性能
支持自定義佈局:可將TitleBar當作FrameLayout使用,直接在XML中自定義佈局測試
兼容沉浸式狀態欄:兼容Github的沉浸式狀態欄框架,達到徹底沉浸的效果
框架兼容性良好:本框架不依賴任何第三方庫,支持兼容全部的安卓版本
支持全局配置樣式:能夠在Application中初始化TitleBar樣式,達到一勞永逸的效果