From 7441fcd156ee26f2e04db21688e75580c8efa03e Mon Sep 17 00:00:00 2001 From: Awesome <1760316362@qq.com> Date: Thu, 23 May 2019 23:14:36 +0800 Subject: [PATCH] TitleBar --- .../java/io/legado/app/ui/widget/TitleBar.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt index be1fafbf7..548c22ec5 100644 --- a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt @@ -7,6 +7,8 @@ import android.graphics.drawable.Drawable import android.util.AttributeSet import android.view.Menu import android.view.View +import androidx.annotation.ColorInt +import androidx.annotation.StyleRes import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.Toolbar import androidx.core.graphics.drawable.DrawableCompat @@ -79,6 +81,38 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a toolbar.setNavigationOnClickListener(clickListener) } + fun setTitle(title: CharSequence?) { + toolbar.title = title + } + + fun setTitle(titleId: Int) { + toolbar.setTitle(titleId) + } + + fun setSubTitle(subtitle: CharSequence?) { + toolbar.subtitle = subtitle + } + + fun setSubTitle(subtitleId: Int) { + toolbar.setSubtitle(subtitleId) + } + + fun setTitleTextColor(@ColorInt color: Int){ + toolbar.setTitleTextColor(color) + } + + fun setTitleTextAppearance(@StyleRes resId: Int){ + toolbar.setTitleTextAppearance(context, resId) + } + + fun setSubTitleTextColor(@ColorInt color: Int){ + toolbar.setSubtitleTextColor(color) + } + + fun setSubTitleTextAppearance(@StyleRes resId: Int){ + toolbar.setSubtitleTextAppearance(context, resId) + } + private fun attachToActivity(context: Context) { val activity = getCompatActivity(context) activity?.let {