Drawable TintDrawable(Drawable drawable, int tint) { Drawable tintedDrawable = DrawableCompat.Wrap(drawable); DrawableCompat.SetTint(tintedDrawable, tint); return(tintedDrawable); }
void ApplyMinTrackTintColor(string propertyName) { if (propertyName == null || propertyName == SliderGloss.MinTrackTintColorProperty.PropertyName) { var minTrackTintColor = (Color)Element.GetValue(SliderGloss.MinTrackTintColorProperty); // Skip assigning anything if all properties are being applied and the color is set to the default value if (propertyName != null || minTrackTintColor != Color.Default) { var aMinTrackTintColor = (minTrackTintColor == Color.Default) ? ThemeUtil.IntToColor(ThemeUtil.ColorAccent(Control.Context, ThemeUtil.DefaultColorControlTrackActivated)) : minTrackTintColor.ToAndroid(); if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { // FYI: Lollipop (API 21) has a broken implementation for the ProgressTintList property. // Assigning a value to the property causes the entire track to be colored with the assigned // value, instead of just the track to the left of the thumb. It works as expected on API 22+. Control.ProgressTintList = ColorStateList.ValueOf(aMinTrackTintColor); } else if (XFGloss.Droid.Library.UsingAppCompat) { DrawableCompat.SetTint(DrawableCompat.Wrap(Control.ProgressDrawable), aMinTrackTintColor); // We also have to explicitly set the MaxTrackTintColor to either the specified custom color or // the default color. Otherwise, setting the MinTrackTintColor tints both the left and right // sides of the track ApplyMaxTrackTintColor(null, true); } else { Console.WriteLine(XFGloss.Droid.Library.appCompatWarning); } } } }
/* * private void OnButtonClick(object sender, EventArgs e) * { * if (sender is AppCompatImageButton imgButton) * Toast.MakeText(this, (string)imgButton.Tag, ToastLength.Short).Show(); * * } */ private void SetUpToolbar() { // Not having raised AppBar area, so don't set SupportActionBar //SetSupportActionBar(_toolbar); // Set the page Title - Required because of the way that Android sets up app asset names _toolbar.Title = null; // using the custom title so it can be centered SetToolbarCustomTitle(ViewModel.Response.Name); // Set the subtitle // SetToolbarCustomSubtitle("Subtitle"); // _toolbar.Subtitle = "Subtitle"; var closeIcon = ResourcesCompat.GetDrawable(Resources, Resource.Drawable.lclose, null).Mutate(); DrawableCompat.SetTint(closeIcon, Color.White); _toolbar.NavigationIcon = closeIcon; var toolbarColor = Constants.GetIconSettingsFromTitle(this, ViewModel.Response.Name).Item2; Window.SetStatusBarColor(toolbarColor); _toolbar.SetBackgroundColor(toolbarColor); // Set toolbar title colors _toolbar.SetTitleTextColor(Color.White); _toolbar.SetSubtitleTextColor(Color.White); SetToolbarCustomTitleColor(Color.White); SetToolbarCustomSubtitleColor(Color.White); }
public static Drawable TintDrawable(this Drawable drawable, Color color) { drawable = DrawableCompat.Wrap(drawable); DrawableCompat.SetTint(drawable.Mutate(), color); return(drawable); }
private void UpdateButton(bool emoji) { try { if (IsShowing == emoji) { return; } IsShowing = emoji; if (emoji) { Drawable dr = AppCompatResources.GetDrawable(ActivityContext, Resource.Drawable.ic_action_keyboard); DrawableCompat.SetTint(DrawableCompat.Wrap(dr), Color.Black); EmojisViewImage.SetImageDrawable(dr); } else { Drawable dr = AppCompatResources.GetDrawable(ActivityContext, Resource.Drawable.ic_action_sentiment_satisfied_alt); DrawableCompat.SetTint(DrawableCompat.Wrap(dr), Color.Black); EmojisViewImage.SetImageDrawable(dr); } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
public void OnLoadStickerCategory(View icon, IStickerCategory stickerCategory, bool selected) { try { var image = (ImageView)icon; if (image != null) { if (stickerCategory is ShopStickers shopStickers) { Drawable dr0 = AppCompatResources.GetDrawable(icon.Context, (int)shopStickers.CategoryData); Drawable dr = dr0.GetConstantState()?.NewDrawable(); if (selected) { DrawableCompat.SetTint(DrawableCompat.Wrap(dr), AXEmojiManager.EmojiViewTheme.SelectedColor); } else { DrawableCompat.SetTint(DrawableCompat.Wrap(dr), AXEmojiManager.EmojiViewTheme.DefaultColor); } image?.SetImageDrawable(dr); } else { Glide.With(icon).Load(Integer.ValueOf(stickerCategory.CategoryData.ToString())).Apply(RequestOptions.FitCenterTransform()).Into(image); } } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> e) { base.OnElementChanged(e); var searchPlateId = Control.Resources.GetIdentifier("android:id/search_plate", null, null); if (searchPlateId != 0) { var v = FindViewById <AView>(searchPlateId); v.Background.SetColorFilter(AColor.White, PorterDuff.Mode.Multiply); } var searchButtonId = Control.Resources.GetIdentifier("android:id/search_mag_icon", null, null); if (searchButtonId != 0) { var image = FindViewById <ImageView>(searchButtonId); if (image != null && image.Drawable != null) { DrawableCompat.SetTint(image.Drawable, ContextCompat.GetColor(Context, Android.Resource.Color.White)); } } }
protected override ProgressBar CreateNativeControl() { pBarBackDrawable = DrawableCompat.Wrap(Resources.GetDrawable("CircularProgress_background")); pBarForeDrawable = DrawableCompat.Wrap(Resources.GetDrawable("CircularProgress_drawable")); DrawableCompat.SetTint(pBarBackDrawable, Element.BackColor.ToAndroid()); DrawableCompat.SetTint(pBarForeDrawable, Element.ForeColor.ToAndroid()); var nativeControl = new ProgressBar(this.Context, null, global::Android.Resource.Attribute.ProgressBarStyleHorizontal) { Indeterminate = false, Max = Element.Maximun, ProgressDrawable = pBarForeDrawable, Rotation = -90f, LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent), }; if (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.Kitkat) { nativeControl.SetBackgroundDrawable(pBarBackDrawable); } else { nativeControl.SetBackground(pBarBackDrawable); } return(nativeControl); }
public void OnPageChanged(AXEmojiPager emojiPager, AXEmojiBase @base, int position) { try { Drawable drawable; if (AXEmojiManager.IsAXEmojiView(@base)) { drawable = AppCompatResources.GetDrawable(Context, Resource.Drawable.emoji_backspace); Utils.EnableBackspaceTouch(Footer, emojiPager.EditText); Footer.SetOnClickListener(null); } else { drawable = AppCompatResources.GetDrawable(Context, Resource.Drawable.ic_action_search); Footer.SetOnTouchListener(null); Footer.SetOnClickListener(this); } DrawableCompat.SetTint(DrawableCompat.Wrap(drawable), AXEmojiManager.EmojiViewTheme.FooterItemColor); Img.SetImageDrawable(drawable); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
private Drawable Wrap(Drawable drb, int tint) { var compat = DrawableCompat.Wrap(drb); DrawableCompat.SetTint(compat, tint); return(compat); }
void ApplyThumbTintColor(string propertyName) { if (propertyName == null || propertyName == SliderGloss.ThumbTintColorProperty.PropertyName) { var thumbTintColor = (Color)Element.GetValue(SliderGloss.ThumbTintColorProperty); // Skip assigning anything if all properties are being applied and the color is set to the default value if (propertyName != null || thumbTintColor != Color.Default) { var aThumbTintColor = (thumbTintColor == Color.Default) ? ThemeUtil.IntToColor(ThemeUtil.ColorAccent(Control.Context, ThemeUtil.DefaultColorControlThumb)) : thumbTintColor.ToAndroid(); if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { Control.ThumbTintList = ColorStateList.ValueOf(aThumbTintColor); } else if (XFGloss.Droid.Library.UsingAppCompat) { DrawableCompat.SetTint(DrawableCompat.Wrap(Control.Thumb), aThumbTintColor); } else { Console.WriteLine(XFGloss.Droid.Library.appCompatWarning); } } } }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e) { base.OnElementChanged(e); if (Android.OS.Build.VERSION.SdkInt <= Android.OS.BuildVersionCodes.Kitkat) { return; } if (e.OldElement != null) { btn.Click -= Btn_Click; } if (e.NewElement != null) { btn = new AppCompatButton(base.Context); btn.Click += Btn_Click; btn.Enabled = Element.IsEnabled; if (((MaterialButton)Element).IsFlat) { btn.StateListAnimator = new Android.Animation.StateListAnimator(); } Drawable drawable = DrawableCompat.Wrap(btn.Background); DrawableCompat.SetTint(drawable.Mutate(), Element.BackgroundColor.ToAndroid()); SetNativeControl(btn); SetTextColor(btn.Enabled); } }
public static Drawable GetIconDrawable(Context context, int drawableRes, Color color) { try { var mDrawable = ContextCompat.GetDrawable(context, drawableRes); if (!(mDrawable is VectorDrawable) || ColoredIcons.Contains(drawableRes)) { return(mDrawable); } try { var mWrappedDrawable = mDrawable.Mutate(); mWrappedDrawable = DrawableCompat.Wrap(mWrappedDrawable); DrawableCompat.SetTint(mWrappedDrawable, color); DrawableCompat.SetTintMode(mWrappedDrawable, PorterDuff.Mode.SrcIn); return(mWrappedDrawable); } catch (Exception ex) { xLog.Error(ex); return(mDrawable); } } catch (Exception ex) { xLog.Error(ex); return(null); } }
private void ChangeTintColor() { if (!_materialIcon.TintColor.IsDefault) { var tintColor = _materialIcon.TintColor.ToAndroid(); DrawableCompat.SetTint(this.Control.Drawable, tintColor); } }
private Drawable GetDrawable(int resource) { var drawable = DrawableCompat.Wrap(VectorDrawableCompat.Create(Resources, resource, Context.Theme)); var value = new TypedValue(); Context.Theme.ResolveAttribute(Resource.Attribute.colorAccent, value, true); DrawableCompat.SetTint(drawable, value.Data); return(drawable); }
/// <summary> /// Helper method used to assign a tint color to the specified layer if it exists. /// </summary> /// <param name="drawable">Drawable.</param> /// <param name="index">Index.</param> /// <param name="color">Color.</param> public static void SetLayerTint(LayerDrawable drawable, int index, Color color) { if (drawable?.NumberOfLayers > index) { var layer = drawable.GetDrawable(index); var wrapper = DrawableCompat.Wrap(layer); DrawableCompat.SetTint(wrapper, color); } }
private void ChangeTintColor(Drawable drawable) { if (!_materialIcon.TintColor.IsDefault && drawable != null) { var tintColor = _materialIcon.TintColor.ToAndroid(); DrawableCompat.SetTint(drawable, tintColor); this.Control.SetImageDrawable(drawable); } }
public DrawerAroundAdapter(Context context) { this.context = context; this.manager = FavoriteManager.Obtain(context); this.starDrawable = DrawableCompat.Wrap(ContextCompat.GetDrawable(context, Resource.Drawable.ic_small_star)); DrawableCompat.SetTint(starDrawable, ContextCompat.GetColor(context, Resource.Color.white_tint_secondary)); this.favorites = new HashSet <Int32> (); LoadFavorites(); }
public static void SetDrawableTint(this Drawable drawable, Color tint) { if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { drawable.SetTint(tint); } else { DrawableCompat.SetTint(drawable, tint); } }
private void ChangeTintColor(Drawable drawable) { if (_materialIcon.TintColor.IsDefault || drawable == null) { return; } var tintColor = _materialIcon.TintColor.ToAndroid(); DrawableCompat.SetTint(drawable, tintColor); Control.SetImageDrawable(drawable); }
private Drawable getColoredArrow() { Drawable arrowDrawable = Resources.GetDrawable(Resource.Drawable.abc_ic_ab_back_material); //abc_ic_ab_back_mtrl_am_alpha Drawable wrapped = DrawableCompat.Wrap(arrowDrawable); if (arrowDrawable != null && wrapped != null) { // This should avoid tinting all the arrows arrowDrawable.Mutate(); DrawableCompat.SetTint(wrapped, Color.Gray); } return(wrapped); }
protected override void Render() { var native = Native; var element = Element; // Visibility if (element.Visibility == Visibility.Visible) { // Icon var iconUri = (element.Icon as BitmapIcon)?.UriSource; if (iconUri != null) { native.NavigationIcon = DrawableHelper.FromUri(iconUri); } // Foreground var foreground = (element.Foreground as SolidColorBrush); var foregroundOpacity = foreground?.Opacity ?? 0; if (FeatureConfiguration.AppBarButton.EnableBitmapIconTint) { var foregroundColor = foreground?.Color; if (native.NavigationIcon != null) { if (foreground != null) { DrawableCompat.SetTint(native.NavigationIcon, (Android.Graphics.Color)foregroundColor); } else { DrawableCompat.SetTintList(native.NavigationIcon, null); } } } // Label native.NavigationContentDescription = element.Label; // Opacity var opacity = element.Opacity; var finalOpacity = foregroundOpacity * opacity; var alpha = (int)(finalOpacity * 255); native.NavigationIcon?.SetAlpha(alpha); } else { native.NavigationIcon = null; native.NavigationContentDescription = null; } }
/** * Return a tint drawable * * @param drawable * @param color * @param forceTint * @return */ public static Drawable getTintDrawable(Drawable drawable, int color, bool forceTint) { if (forceTint) { drawable.ClearColorFilter(); drawable.SetColorFilter(new Color(color), PorterDuff.Mode.SrcIn); drawable.InvalidateSelf(); return(drawable); } Drawable wrapDrawable = DrawableCompat.Wrap(drawable).Mutate(); DrawableCompat.SetTint(wrapDrawable, color); return(wrapDrawable); }
public static void SetDrawableTint(this Drawable drawable, Color tint, bool correctEnabled = false) { if (tint != null) { if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { drawable.SetTint(tint); } else { DrawableCompat.SetTint(drawable, tint); } } }
//http://stackoverflow.com/questions/26788464/how-to-change-color-of-the-back-arrow-in-the-new-material-theme //http://gregshackles.com/changing-the-android-toolbars-back-arrow-color/ public Drawable ChangeColorTint(Drawable drawable, int colorTint) { if (drawable == null) { return(null); } var wrapped = DrawableCompat.Wrap(drawable); // This should avoid tinting all the arrows wrapped = wrapped.Mutate(); DrawableCompat.SetTint(wrapped, colorTint); return(wrapped); }
public override bool OnPrepareOptionsMenu(IMenu menu) { base.OnPrepareOptionsMenu(menu); var menuItem = menu.Add(0, toggleFormHighlightColorMenuItemId, 0, "Toggle highlight color"); menuItem.SetShowAsAction(ShowAsAction.Always); var tintedDrawable = DrawableCompat.Wrap(ContextCompat.GetDrawable(this, Resource.Drawable.pspdf__ic_highlight)); DrawableCompat.SetTint(tintedDrawable, Color.White); menuItem.SetIcon(tintedDrawable); return(true); }
public static Drawable WrapTintDrawable(Drawable sourceDrawable, int color) { if (color != 0) { Drawable wrapDrawable = DrawableCompat.Wrap(sourceDrawable); DrawableCompat.SetTint(wrapDrawable, color); wrapDrawable.SetBounds(0, 0, wrapDrawable.IntrinsicWidth, wrapDrawable.IntrinsicHeight); return(wrapDrawable); } else { return(sourceDrawable); } }
private static void CorrectDrawableTint(Drawable drw, ColorStateList tint) { // A bug means _drawableCenter seems to only be picking up the disabled colour from the ColorStateList, so set color manually // Mutating the drawable doesn't fix the issue, not sure what is causing it. Color defaultColor = new Color(tint.DefaultColor); int enabledColorInt = tint.GetColorForState(new int[] { global::Android.Resource.Attribute.StateEnabled }, defaultColor); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { drw.SetTint(enabledColorInt); } else { DrawableCompat.SetTint(drw, enabledColorInt); } }
public override bool OnPrepareOptionsMenu(IMenu menu) { base.OnPrepareOptionsMenu(menu); var collaborateMenuItem = menu.Add(0, Resource.Id.instant_collaborate, 0, "Collaborate"); collaborateMenuItem.SetShowAsAction(ShowAsAction.Always); collaborateMenuItem.SetEnabled(Document != null); var drawable = ContextCompat.GetDrawable(this, Resource.Drawable.ic_collaborate); drawable.SetAlpha(Document is null ? 128 : 255); DrawableCompat.SetTint(drawable, mainToolbarIconsColor); collaborateMenuItem.SetIcon(drawable); return(true); }
/// <summary> /// Dynamically add links associated with each business and on-click functions to these links, which are inserted into the LinearLayout _layoutBusLink. /// </summary> private void addBusLinks() { foreach (var link in _businessObj.LinkList) { // Create New Views LinearLayout _layoutSingleLink = new LinearLayout(this); ImageView _iconSingleLink = new ImageView(this); TextView _textSingleLink = new TextView(this); // Set Link Layout Attributes float scale = this.ApplicationContext.Resources.DisplayMetrics.Density; int layoutPixels = (int)(70 * scale + 0.5f);//layoutPixels is equivalent to 70dp LinearLayout.LayoutParams _layoutSingleLinkParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, layoutPixels, 1f); _layoutSingleLink.LayoutParameters = _layoutSingleLinkParams; _layoutSingleLink.Orientation = Orientation.Horizontal; // Set Link ImageView Attributes LinearLayout.LayoutParams _iconSingleLinkParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent, 1f); _iconSingleLink.LayoutParameters = _iconSingleLinkParams; Android.Graphics.Drawables.Drawable linkIcon = Android.Support.V4.Content.ContextCompat.GetDrawable(this.ApplicationContext, Resource.Drawable.ic_link_black_24dp); linkIcon = DrawableCompat.Wrap(linkIcon); DrawableCompat.SetTint(linkIcon.Mutate(), Android.Support.V4.Content.ContextCompat.GetColor(this.ApplicationContext, Resource.Color.cscBlue)); _iconSingleLink.SetImageDrawable(linkIcon); // Set Link TextView Attributes LinearLayout.LayoutParams _textSingleLinkParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent, 4f); int textPixels = (int)(5 * scale + 0.5f);//textPixels is equivalent to 5dp _textSingleLinkParams.BottomMargin = textPixels; _textSingleLink.TextSize = 20; _textSingleLink.LayoutParameters = _textSingleLinkParams; _textSingleLink.SetTextColor(Android.Support.V4.Content.ContextCompat.GetColorStateList(this.ApplicationContext, Resource.Color.cscBlue)); _textSingleLink.Text = link.Name; // Set on-click action _layoutSingleLink.SetTag(link.Name.GetHashCode(), link.URI); _layoutSingleLink.Clickable = true; _layoutSingleLink.Click += _txtBusLink_Click; // Add views to layout _layoutSingleLink.AddView(_iconSingleLink); _layoutSingleLink.AddView(_textSingleLink); _layoutBusLinks.AddView(_layoutSingleLink); } }