pull/31/head
Awesome 6 years ago
parent 57acb76df6
commit b8175f9fbb
  1. 29
      app/src/main/java/io/legado/app/ui/widget/TitleBar.kt
  2. 2
      app/src/main/res/layout/activity_search.xml
  3. 6
      app/src/main/res/values/attrs.xml

@ -33,16 +33,43 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a
val navigationIconTintMode = a.getInt(R.styleable.TitleBar_navigationIconTintMode, 9)
val showNavigationIcon = a.getBoolean(R.styleable.TitleBar_showNavigationIcon, true)
val attachToActivity = a.getBoolean(R.styleable.TitleBar_attachToActivity, true)
val titleText = a.getString(R.styleable.TitleBar_title)
val subtitleText = a.getString(R.styleable.TitleBar_subtitle)
a.recycle()
if (showNavigationIcon) {
toolbar.apply {
if(showNavigationIcon){
this.navigationIcon = navigationIcon
this.navigationContentDescription = navigationContentDescription
wrapDrawableTint(this.navigationIcon, navigationIconTint, navigationIconTintMode)
}
if (a.hasValue(R.styleable.TitleBar_titleTextAppearance)) {
this.setTitleTextAppearance(context, a.getResourceId(R.styleable.TitleBar_titleTextAppearance, 0))
}
if (a.hasValue(R.styleable.TitleBar_titleTextColor)) {
this.setTitleTextColor(a.getColor(R.styleable.TitleBar_titleTextColor, -0x1))
}
if (a.hasValue(R.styleable.TitleBar_subtitleTextAppearance)) {
this.setSubtitleTextAppearance(context, a.getResourceId(R.styleable.TitleBar_subtitleTextAppearance, 0))
}
if (a.hasValue(R.styleable.TitleBar_subtitleTextColor)) {
this.setSubtitleTextColor(a.getColor(R.styleable.TitleBar_subtitleTextColor, -0x1))
}
if(!titleText.isNullOrBlank()){
this.title = titleText
}
if(!subtitleText.isNullOrBlank()){
this.subtitle = subtitleText
}
}
if (attachToActivity) {
attachToActivity(context)
}

@ -17,7 +17,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
/>
app:title="搜索"/>
<io.legado.app.ui.widget.dynamiclayout.DynamicFrameLayout
android:layout_width="match_parent"

@ -2,6 +2,12 @@
<resources>
<declare-styleable name="TitleBar">
<attr name="title" />
<attr name="subtitle" />
<attr name="titleTextAppearance" />
<attr name="titleTextColor" />
<attr name="subtitleTextAppearance" />
<attr name="subtitleTextColor" />
<attr name="attachToActivity" format="boolean" />
<attr name="showNavigationIcon" format="boolean" />
<attr name="navigationIcon" format="reference" />

Loading…
Cancel
Save