I'm trying to set the foreground on an AppCompatImageView in my app, but android studio is telling me that the getForeground()
and setForeground
methods require api 23. I thought this was a little odd given how simple it seems, so I checked the reference at this link and saw that the method getForeground
was added in api 1.
So, thinking that it was just some sort of error in Android studio, I fired up my emulator of a Nexus 5x on api 19 to check. When I clicked my view(which triggers setting the foreground), the app crashed giving me a methodnotfoundexception
.
This is kind of confusing to me because obviously api 19 doesn't have that method otherwise my app wouldn't have crashed, but the documentation does pretty clearly say that the foreground methods in the View class were added in api 1. Furthermore, I can set the foreground in the XML of my activity without android studio complaining, but in api 19, the foreground doesn't actually show up. Does that mean that the foreground methods are only for internal use before api 23?
This is a known documentation bug. Those methods were introduced in Android 6.0 (API Level 23).