From 4abfb9069f1b18a4f600f9bd77a3e9250e899752 Mon Sep 17 00:00:00 2001 From: Colby Williams Date: Tue, 22 Nov 2016 16:14:20 -0500 Subject: [PATCH] color the status bar and navigation bar --- XWeather/Droid/Activities/WeatherActivity.cs | 37 +++++++++++++++++++ XWeather/Droid/Properties/AndroidManifest.xml | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/XWeather/Droid/Activities/WeatherActivity.cs b/XWeather/Droid/Activities/WeatherActivity.cs index 68519af..5d2f486 100644 --- a/XWeather/Droid/Activities/WeatherActivity.cs +++ b/XWeather/Droid/Activities/WeatherActivity.cs @@ -2,9 +2,12 @@ using System.Threading.Tasks; using Android.App; +using Android.Animation; +using Android.Graphics; using Android.Graphics.Drawables; using Android.OS; using Android.Views; +using Android.Views.Animations; using Android.Support.Design.Widget; using Android.Support.V4.View; @@ -157,6 +160,9 @@ void updateBackground () viewPager.Background = gd; + Window.SetStatusBarColor (gradients.Item1 [0]); + Window.SetNavigationBarColor (gradients.Item1 [1]); + } else { var backgrounds = new Drawable [2]; @@ -169,6 +175,37 @@ void updateBackground () viewPager.Background = crossfader; crossfader.StartTransition (1000); + + var statusBarAnimator = ValueAnimator.OfArgb (Window.StatusBarColor, gradients.Item1 [0]); + + statusBarAnimator.SetDuration (1000); + statusBarAnimator.SetInterpolator (new AccelerateDecelerateInterpolator ()); + + statusBarAnimator.Update += (sender, e) => { + + var val = e.Animation.AnimatedValue as Java.Lang.Integer; + + var color = new Color ((int)val); + + Window.SetStatusBarColor (color); + }; + + var naviationBarAnimator = ValueAnimator.OfArgb (Window.NavigationBarColor, gradients.Item1 [1]); + + naviationBarAnimator.SetDuration (1000); + naviationBarAnimator.SetInterpolator (new AccelerateDecelerateInterpolator ()); + + naviationBarAnimator.Update += (sender, e) => { + + var val = e.Animation.AnimatedValue as Java.Lang.Integer; + + var color = new Color ((int)val); + + Window.SetNavigationBarColor (color); + }; + + statusBarAnimator.Start (); + naviationBarAnimator.Start (); } } } diff --git a/XWeather/Droid/Properties/AndroidManifest.xml b/XWeather/Droid/Properties/AndroidManifest.xml index 6f036d0..26413dc 100644 --- a/XWeather/Droid/Properties/AndroidManifest.xml +++ b/XWeather/Droid/Properties/AndroidManifest.xml @@ -1,7 +1,7 @@