, attrs: AttributeSet?=null) : PagerTabStrip(context, attrs) {
private var txtColor = Color.BLACK
private var textSize = 15
init {
txtColor = Color.BLACK
textSize = 15
//初始化时从attrs.xml读取CustomPagerTab的自定义属性
if (attrs != null) {
val attrArray = getContext().obtainStyledAttributes(attrs, R.styleable.CustomPagerTab)
txtColor = attrArray.getColor(R.styleable.CustomPagerTab_textColor, txtColor)
textSize = attrArray.getDimensionPixelSize(R.styleable.CustomPagerTab_textSize, textSize)
attrArray.recycle()
}
setTextColor(txtColor)
setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize.toFloat())
}
}
完成以上三步修改后,运行测试应用,展示的界面效果如下图所示,此时翻页标题栏的文字颜色变为红色,而且字体也变大了。
|