title: Reload Localized Layout After Locale Changed in Service
body: <p>I have a keyboard service which displays a soft keyboard input to the end user. I am planning on expanding this to support multiple languages, though I am running into a problem when attempting to reload the layout file with a new localization.</p>
  
  <p>My problem is that when a configuration change is triggered, the strings update with their new localized version based on the locale, but the layout does not change to reflect the new locale.</p>
  
  <p>For example, I have this bit of code:</p>
  
  <pre><code>//Update configuration to reload localization
  Configuration config = getResources().getConfiguration();
  config.setLocale(locale); //locale is a Locale object for Spanish (Spain)
  getBaseContext().getResources().updateConfiguration(config, null);
  </code></pre>
  
  <p>This is called from a class which <code>extends InputMethodService</code> and <code>implements OnKeyboardActionListener</code></p>
  
  <p>This will trigger a configuration change, and as a result when the keyboard view appears I can see that some of the strings used have changed over to Spanish. However, it seems the layout has not been reloaded.</p>
  
  <p>For reference, I have the following <code>xml</code> files:</p>
  
  <p><code>layout_qwerty.xml</code> (some information redacted)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Keyboard&gt;
      &lt;Row&gt;
          &lt;Key/&gt;
  ...
          &lt;Key/&gt;
      &lt;/Row&gt;
  &lt;/Keyboard&gt;
  </code></pre>
  
  <p><code>layout_qwerty.xml (es)</code> (some information redacted)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Keyboard&gt;
      &lt;Row&gt;
          &lt;Key/&gt; &lt;!-- Some different key here, say ñ --&gt;
  ...
          &lt;Key/&gt;
      &lt;/Row&gt;
  &lt;/Keyboard&gt;
  </code></pre>
  
  <p><code>strings.xml</code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
      &lt;string name="label_enter_key"&gt;Enter&lt;/string&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p><code>strings.xml (es)</code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
      &lt;string name="label_enter_key"&gt;Intro&lt;/string&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>I know that this works in theory because using the default Android <code>LocalePicker</code> to change localization updates the keyboard view with the new layout as well as the new strings. It's only when performing the configuration change myself programmatically that I do not see the layout updated, only the strings. Looking in Android source code at what <code>LocalePicker</code> does to trigger the configuration change uses hidden classes and functions which are inaccessible from a top level application, so I don't think I am able to do the same. (see <a href="http://androidxref.com/6.0.1_r10/xref/frameworks/base/core/java/com/android/internal/app/LocalePicker.java" rel="nofollow noreferrer">updateConfiguration</a> method for reference)</p>
  
  <p>Here are some images showing the difference between changing locale via application code and changing it via the native Android <code>LocalePicker</code>:</p>
  
  <p>Full English (Default state)
  <a href="https://i.stack.imgur.com/L44PC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L44PC.png" alt="Full English (Default state)"></a></p>
  
  <p>Half Spanish (Locale changed via application code)
  <a href="https://i.stack.imgur.com/v7MR1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v7MR1.png" alt="Half Spanish (Locale changed via applicatio code); notice that the soft keys are translated but the layout is the same, so there is no ñ key"></a></p>
  
  <p>Full Spanish (Locale changed via native Android <code>LocalePicker</code>)
  <a href="https://i.stack.imgur.com/iI6jR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iI6jR.png" alt="Full Spanish (Locale changed via native Android &lt;code&gt;LocalePicker&lt;/code&gt;); notice we now have the ñ key"></a></p>
  
  <p>Notice how only in the last image we have the ñ key available, showing that our layout was properly reloaded.</p>
  
  <p>I have tried things like invalidating the view (e.g. <code>mInputView.invalidate()</code>) and manually calling <code>onCreateInputView()</code> but after redraw the view still showed the old layout.</p>
  
  <p>Is there anything I can do to reload the layout after locale change?</p>