1

Say I have below style.xml file in android studio:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.MyTheme" parent="Theme.AppCompat">
        <item name="android:colorForeground">@color/purple_200</item>
    </style>
</resources>

How can I write code in java to read out the hex value of "android:colorForeground"?

lucky1928
  • 8,708
  • 10
  • 43
  • 92

1 Answers1

1

do you want like this???

val attr = intArrayOf(android.R.attr.colorForeground)
val typed = obtainStyledAttributes(R.style.{the style name}, attr)
val foreCorlor = typed.getColorOrThrow(0)
typed.recyle() // very very important
개구신
  • 46
  • 5