How to get accent color programmatically?

前端 未结 7 2396
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 03:32

How would one fetch the accent color set in styles, like below, programmatically?

    @color/material_green_500<         


        
7条回答
  •  时光说笑
    2020-12-05 04:30

    For those of you using Kotlin

    fun Context.themeColor(@AttrRes attrRes: Int): Int {
        val typedValue = TypedValue()
        theme.resolveAttribute (attrRes, typedValue, true)
        return typedValue.data
    }
    

提交回复
热议问题