I need to get the Color of the default background color of the App in Code.
up until now i used R.attr.colorSurface to get this, but somehow lately this gives me the incorrect color on some devices.
when i use this function, I'm getting a dark color in light theme and blue in dark theme
public static int getThemeColor2(Context context, int android_r)
{
if(context == null)
return 0x000000;
// https://stackoverflow.com/a/17277714/1683382
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(android_r, typedValue, true);
@ColorInt int color = typedValue.data;
return color;
}
when i use this code, I'm getting yellow-white in light and light pink in dark theme
MaterialColors.getColor(context, R.attr.colorSurface, Color.BLACK);
for all other theme colors i can use R.attr like R.attr.colorPrimary, R.attr.colorSecondary etc but I'm just not able to get the background color correctly now matter what i try.
what is the correct way to get this color?
Some notes:
R.attr.backgroundColor gives me 0x000000
colorOnBackground exists but colorBackground does not?
what is colorBackgroundFloating ?
is it just me, or is the whole Theme Color a total mess. There is no complete overview and multiple functions that gives you different results