Commit ebe280ae authored by yinjiacheng's avatar yinjiacheng

update 通用TopBar属性支持代码设置

parent 5cba4e51
......@@ -6,6 +6,8 @@ import android.util.AttributeSet
import android.view.View
import android.view.ViewTreeObserver
import android.view.WindowManager
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
......@@ -66,7 +68,7 @@ class CommonTopBarView @JvmOverloads constructor(
viewBinding.tvAction.isVisible = action.isNotEmpty()
viewBinding.tvAction.text = action
// 设置背景色
viewBinding.root.setBackgroundColor(
setBackgroundColor(
typeArray.getColor(
R.styleable.CommonTopBarView_CommonTopBarView_bg_color,
ContextCompat.getColor(context, R.color.transparent)
......@@ -96,12 +98,41 @@ class CommonTopBarView @JvmOverloads constructor(
}
/**
* 设置title
* 设置标题
*/
fun setTitle(title: String) {
viewBinding.tvTitle.text = title
}
/**
* 设置标题文字颜色
*/
fun setTitleTextColor(@ColorInt color: Int) {
viewBinding.tvTitle.setTextColor(color)
}
/**
* 设置背景色
*/
fun setRootBackgroundColor(@ColorInt color: Int) {
setBackgroundColor(color)
}
/**
* 设置返回按钮图标
*/
fun setBackImageResource(@DrawableRes resource: Int) {
viewBinding.ivBack.setImageResource(resource)
}
/**
* 设置横向内边距
* @param padding 单位: px
*/
fun setRootHorizontalPadding(padding: Int) {
setPadding(padding, 0, padding, 0)
}
/**
* 设置返回按钮是否可见
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment