Created
November 30, 2017 22:35
-
-
Save rdelrosario/77b816bf0ceed5ea54c8fe27012bd79a to your computer and use it in GitHub Desktop.
Android - Shadow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void UpdateToolbarShadow(Android.Support.V7.Widget.Toolbar toolbar, bool hasShadow, Activity activity, Android.Graphics.Drawables.Drawable windowContent) | |
{ | |
var androidContent = activity?.Window?.DecorView?.FindViewById<FrameLayout>(Window.IdAndroidContent); | |
if (androidContent != null) | |
{ | |
if (hasShadow && activity != null) | |
{ | |
GradientDrawable shadowGradient = new GradientDrawable(GradientDrawable.Orientation.RightLeft, new int[] { Android.Graphics.Color.Transparent.ToArgb(), Android.Graphics.Color.Gray.ToArgb() }); | |
shadowGradient.SetCornerRadius(0f); | |
androidContent.Foreground = shadowGradient; | |
toolbar.Elevation = 4; | |
} | |
else | |
{ | |
androidContent.Foreground = windowContent; | |
toolbar.Elevation = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment