kotlin - 更改高度和颜色选项卡指示器
问题描述
我正在尝试在自定义选项卡布局中更改棕褐色指示器的高度和颜色,但我无法做到。这是我通常在我的应用程序中使用的自定义组件。
我正在尝试通过代码更改高度和颜色,我知道从 xml 中我可以做到这一点。
这是我到目前为止所拥有的:
class CustomTabLayout : TabLayout {
private var mTypeface: Typeface? = null
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
) {
init()
}
private fun init() {
mTypeface = ResourcesCompat.getFont(context, R.font.montserrat_medium)
}
override fun addTab(tab: Tab, position: Int, setSelected: Boolean) {
super.addTab(tab, position, setSelected)
val mainView = getChildAt(0) as ViewGroup
val tabView = mainView.getChildAt(tab.position) as ViewGroup
val tabChildCount = tabView.childCount
for (i in 0 until tabChildCount) {
val tabViewChild = tabView.getChildAt(i)
if (tabViewChild is TextView) {
tabViewChild.setTypeface(mTypeface, Typeface.NORMAL)
tabViewChild.isAllCaps = false
}
}
}
}
任何帮助将不胜感激。
解决方案
推荐阅读
- sql-server - 在两个不同的数据库上查询列元数据
- python - setuptools 的角色是什么?后端支持是什么意思?
- r - 工作目录和网络抓取问题
- typescript - 在使用之前的每个夹具之前运行设置
- amazon-web-services - 控制用户在 AWS EMR/EC2 实例中的操作
- complexity-theory - 枚举等价类
- mysql - 如何从该表中选择最近 3 年连续交易的 user_ids?
- firebase - 处理 firestore 权限错误并向用户显示警报对话框
- neo4j - 在neo4j沙箱中,如何将相同标签的节点彼此靠近显示?
- vue.js - Vue中使用路由时如何接收消息