title: How *dynamically* change EVERY color iOS/Android? E.g. in Droid code, override "colorAccent" in "Styles.xml"
body: <p>I am adding color themes to a Xamarin Forms app.
  The theme is spec'ed to <strong>change dynamically</strong> depending on which <strong>client's location</strong> the user is standing at/near. We have both "light" and "dark" themed clients, having a variety of color palettes; so it needs to be possible to change all colors of <strong>all</strong> display items. Dynamically.</p>
  
  <p><strong>So far, my dynamic theming works for <em>almost</em> all types of views.</strong> </p>
  
  <p>I'm <strong>stuck on two details</strong> when coloring the iOS-style (vertical scrolling wheel) <code>Xamarin.Forms.Picker</code> on Android:</p>
  
  <p><strong>Question 1:</strong> How change the background color?<br>
  <strong>Question 2:</strong> How change the "Cancel" button's text color?</p>
  
  <p>This Android <code>NumberPicker</code>-based XF View, doesn't seem to be fully color-customizable out of the box. As of latest XF, 4.3.0.991211.</p>
  
  <hr>
  
  <p><strong>----- What I've tried:-----</strong></p>
  
  <hr>
  
  <p>A. Set Android theme colors <em>statically</em>, in <code>Style.xml</code> resource file. Success. But its static.</p>
  
  <hr>
  
  <p>B. Download <a href="https://docs.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/userinterface-theming/" rel="nofollow noreferrer">Xamarin Forms Light/Dark Theme Sample</a>.</p>
  
  <p>Build and run on Android. Go to its "Select Theme" picker. Pick light theme. Go to picker again - white background, so far, so good. Pick dark theme. Go to picker again - the picker is still black-on-white. No solution here.</p>
  
  <hr>
  
  <p>C. Found online how to dynamically change <code>AlertDialog</code>s "OK"/"Cancel" button text colors, using an AlertDialog "builder", and getting at the resource IDs. Successfully implemented that. Not sure how to apply the same technique to Picker.</p>
  
  <p><strong>Question 3:</strong> How discover what resource IDs are used in the Android Control used by XF Picker?</p>
  
  <hr>
  
  <p>D. Clone Xamarin Forms source code. Copy Droid PickerRenderer into my code. Most of the code can't be run because it depends on <code>internal</code> classes/functions. Make mine inherit from the built-in one, and comment out any code that isn't needed / won't compile.</p>
  
  <p>Customize <code>OnElementChanged</code>, because that is where <code>TextColor</code> is set.</p>
  
  <p>In the custom renderer source code, <code>IPickerRenderer.OnClick()</code> builds an <code>AlertDialog</code> containing a <code>NumberPicker</code>. I don't see any logic that sets Background color or "Cancel" button's text color. But at least we have known Android classes. <em>See Question 3 above.</em></p>
  
  <hr>
  
  <p>E. At a minimum, <strong><a href="https://stackoverflow.com/a/28033500/199364">having a small number of predefined themes</a></strong> might be a solution. Or <a href="https://stackoverflow.com/a/37905131/199364">Android theme.ApplyStyle</a> - but can this be a <em>dynamic</em> style? I haven't yet tested to see if either of these successfully changes the details that I am stuck on. [Will report back after I try.]</p>
  
  <hr>
  
  <p>F. It might be possible by <strong>restarting the app</strong> to change theme: <a href="https://stackoverflow.com/a/48517223/199364">any-color themes</a>. This would be my last resort; first seeing if I can control colors completely from within C#, without a restart.</p>
  
  <hr>
  
  <p>NOTE: There are many posts at SO and Xamarin.Forums that talk <em>generally</em> about theming in Xamarin Forms. I'm past that point, so I won't list those here, except to mention <a href="https://redpillxamarin.com/2018/07/19/2018-104-resources-styles-and-themes/" rel="nofollow noreferrer">Clint St.Laurent's theming post</a>, which (taking a quick glance at it) looks similar to what I've done. <em>All I have left are a small number of tiny details - which Xamarin Forms fails to apply theme colors to, in my testing.</em></p>
  
  <hr>
  
  <p>G. Other SO posts that seem related - but don't do the exact tasks listed in Questions 1 &amp; 2:</p>
  
  <p><a href="https://stackoverflow.com/a/56421729/199364">Picker implemented as an AlertDialog</a>. Shows a custom PickerRenderer. But doesn't show how to set the colors in Q 1 &amp; 2.</p>
  
  <p>Another <a href="https://stackoverflow.com/q/56476142/199364">Picker implemented as an AlertDialog</a>. Likewise.</p>
  
  <p><a href="https://stackoverflow.com/q/25815769/199364">How to really change primary and accent color in android lollipop</a> - I mention answers from this in <code>E</code> and <code>F</code>. If I can't achieve the result via C# code in custom PickerRenderer, I will investigate these.</p>
  
  <hr>
  
  <p>Xamarin Forums posts:</p>
  
  <p><a href="https://forums.xamarin.com/discussion/98614/is-it-possible-to-change-the-coloraccent-at-runtime" rel="nofollow noreferrer">How to change the colorAccent at runtime?</a>. The only answer given doesn't change theme's <code>colorAccent</code>. It just changes the app bar's color.</p>
  
  <hr>
  
  <p><strong>CLARIFICATION:</strong> There are plenty of doc, forum, and blog posts that describe the <em>general</em> mechanism of Xamarin Forms theming. Not looking for answers to that. I'm just looking to resolve <em>a small number of missing details</em>, as of latest stable Xamarin Forms, 4.3.0.991211. <strong>Hopefully the day will come when Xamarin Forms successfully themes 100% of the details of all types of controls - at which time this Question and Answer will be obsolete.</strong></p>