int GetColorPrimaryDark() { FormsAppCompatActivity context = this; int id = global::Android.Resource.Attribute.ColorPrimaryDark; using (var value = new TypedValue()) { try { Resources.Theme theme = context.Theme; if (theme != null && theme.ResolveAttribute(id, value, true)) { if (value.Type >= DataType.FirstInt && value.Type <= DataType.LastInt) { return(value.Data); } if (value.Type == DataType.String) { return(ContextCompat.GetColor(context, value.ResourceId)); } } } catch (Exception ex) { Log.Warning("Xamarin.Forms.Platform.Android.FormsAppCompatActivity", "Error retrieving color resource: {0}", ex); } return(-1); } }
public static void ApplyLevelColors(Resources.Theme theme) { var levelNumber = DataHolder.Current.Levels.IndexOf(DataHolder.Current.CurrentLevel) + 1; // REFLECTION for fields like Level1Colors theme.ApplyStyle((int)(typeof(Resource.Style).GetField(string.Format("Level{0}Colors", levelNumber)).GetValue(null)), true); }
public PinWidget(Context context, IAttributeSet attribs, int defStyleAttr) : base(context, attribs, defStyleAttr) { ShouldRedraw = false; this.FillViewport = true; ScrollBarStyle = ScrollbarStyles.OutsideInset; TypedArray array = context.ObtainStyledAttributes(attribs, Resource.Styleable.PinView); var method = array.GetString(Resource.Styleable.PinView_onPinCompleted); PinListener = new PrivatePinListener(method, this); DigitCount = (uint)array.GetInt(Resource.Styleable.PinView_digitCount, PinDefaults.DIGIT_COUNT); DisplayMetrics metrics = Resources.DisplayMetrics; // Digit dimensions DigitWidth = array.GetDimensionPixelSize(Resource.Styleable.PinView_digitWidth, (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, PinDefaults.DIGIT_WIDTH, metrics)); DigitHeight = array.GetDimensionPixelSize(Resource.Styleable.PinView_digitHeight, (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, PinDefaults.DIGIT_HEIGHT, metrics)); DigitSpacing = array.GetDimensionPixelSize(Resource.Styleable.PinView_digitSpacing, (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, PinDefaults.DIGIT_SPACING, metrics)); TextSize = array.GetDimensionPixelSize(Resource.Styleable.PinView_textSize, (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, PinDefaults.TEXT_SIZE, metrics)); TypedValue resolvedColor = new TypedValue(); Resources.Theme theme = context.Theme; // Colors theme.ResolveAttribute(Android.Resource.Attribute.TextColorPrimary, resolvedColor, true); TextColor = array.GetColor(Resource.Styleable.PinView_textColor, resolvedColor.ResourceId > 0 ? ContextCompat.GetColor(context, resolvedColor.ResourceId) : resolvedColor.Data); DigitBorderColor = array.GetColor(Resource.Styleable.PinView_borderColor, TextColor); resolvedColor = new TypedValue(); theme.ResolveAttribute(Android.Resource.Attribute.ColorAccent, resolvedColor, true); AccentColor = array.GetColor(Resource.Styleable.PinView_accentColor, resolvedColor.ResourceId > 0 ? ContextCompat.GetColor(context, resolvedColor.ResourceId) : resolvedColor.Data); resolvedColor = new TypedValue(); theme.ResolveAttribute(Android.Resource.Attribute.WindowBackground, resolvedColor, true); DigitBackgroundColor = array.GetColor(Resource.Styleable.PinView_digitBackgroundColor, resolvedColor.ResourceId > 0 ? ContextCompat.GetColor(context, resolvedColor.ResourceId) : resolvedColor.Data); AccentHeight = (int)array.GetDimension(Resource.Styleable.PinView_accentHeight, TypedValue.ApplyDimension(ComplexUnitType.Dip, PinDefaults.ACCENT_HEIGHT, metrics)); array.Recycle(); _mainLayout = new LinearLayout(Context); _pinInputField = new EditText(Context); var container = new FrameLayout(Context); container.AddView(_mainLayout); container.AddView(_pinInputField); this.AddView(container); ShouldRedraw = true; }
protected void UpdateBackgroundColor() { if (Element == null) { return; } Color backgroundColor = Element.BackgroundColor; if (backgroundColor.IsDefault) { if (SupportBackgroundTintList != null) { Context context = Context; int id = GlobalResource.Attribute.ButtonTint; unchecked { using (var value = new TypedValue()) { try { Resources.Theme theme = context.Theme; if (theme != null && theme.ResolveAttribute(id, value, true)) #pragma warning disable 618 { SupportBackgroundTintList = Resources.GetColorStateList(value.Data); } #pragma warning restore 618 else { SupportBackgroundTintList = new ColorStateList(ColorExtensions.States, new[] { (int)0xffd7d6d6, 0x7fd7d6d6 }); } } catch (Exception ex) { Internals.Log.Warning("Xamarin.Forms.Platform.Android.ButtonRenderer", "Could not retrieve button background resource: {0}", ex); SupportBackgroundTintList = new ColorStateList(ColorExtensions.States, new[] { (int)0xffd7d6d6, 0x7fd7d6d6 }); } } } } } else { int intColor = backgroundColor.ToAndroid().ToArgb(); int disableColor = backgroundColor.MultiplyAlpha(0.5).ToAndroid().ToArgb(); SupportBackgroundTintList = new ColorStateList(ColorExtensions.States, new[] { intColor, disableColor }); } }
public static int GetThemeColor(Context context, int attribute, int defaultColor) { int themeColor = 0; string packageName = context.PackageName; try { Context packageContext = context.CreatePackageContext(packageName, 0); ApplicationInfo applicationInfo = context.PackageManager.GetApplicationInfo(packageName, 0); packageContext.SetTheme(applicationInfo.Theme); Resources.Theme theme = packageContext.Theme; TypedArray ta = theme.ObtainStyledAttributes(new [] { attribute }); themeColor = ta.GetColor(0, defaultColor); ta.Recycle(); } catch (PackageManager.NameNotFoundException e) { e.PrintStackTrace(); } return(themeColor); }
//http://stackoverflow.com/questions/29041027/android-getresources-getdrawable-deprecated-api-22 public Drawable GetDrawable(Resources resources, int id, Resources.Theme theme) { return(ResourcesCompat.GetDrawable(resources, id, theme)); }
public virtual RequestBuilder SetTheme(Resources.Theme theme) => (RequestBuilder)Theme_T(theme);
public virtual RequestOptions SetTheme(Resources.Theme theme) => (RequestOptions)Theme_T(theme);
public SafeSpinner(Context context, IAttributeSet attrs, int defStyle, int mode, Resources.Theme popupTheme) : base(context, attrs, defStyle, mode, popupTheme) { Initialize(); }
public InstantAutoComplete(Context context, IAttributeSet attrs, int defStyleAttr, int defStyleRes, Resources.Theme popupTheme) : base(context, attrs, defStyleAttr, defStyleRes, popupTheme) { }