c# - Querying the background colour of an app -
i have 2 basic ui designs xamarin.forms app, 1 light backgrounds, , 1 dark backgrounds. basically, icons change white black depending on background colour. have approximated selection of these whether platform ios (light) or android (dark). however, given option android users use skins, wondered if there way of finding out whether phone had light or dark background?
thanks.
you have make platform specific dependency injection service (https://developer.xamarin.com/videos/cross-platform/accessing-native-features-through-the-dependency-service/).
on android use this: https://stackoverflow.com/a/9537629/5064986
to background color:
const int type_first_color_int = 28; const int type_last_color_int = 31; typedvalue = new typedvalue(); theme.resolveattribute(android.resource.attribute.windowbackground, a, true); if (a.type >= type_first_color_int && a.type <= type_last_color_int) { // windowbackground color int color = a.data; // int representation of background color } else { // windowbackground not color, drawable drawable d = resources.getdrawable(a.resourceid); // ... }
Comments
Post a Comment