Search code examples
javaandroidkeyboardpreferencesime

How to handle configuration change in Android keyboard (IME)?


I have been following Android sample provided with the documentation to design new (relatively simple) keyboard. At this point I am stuck with configuration change (like theme, textSize or bit complex stuff) which requires IME to recreate itself.

public class ImePreferences extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.AppTheme_WithActionBar);
        super.onCreate(savedInstanceState);
        PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
        // reload ime
        Log.d("anbani", "Stopping service " + String.valueOf(stopService(new Intent(this, SoftKeyboard.class))));
        Log.d("anbani", "prefs changed");
    }



    ...
}

This does not help. StopService value is returned true but there is no effect.

Is there some trick to get an instance of package keyboard without prior reference to it? Or am missing something simple here?

Any tips would be highly appreciated!


Solution

  • Solution:

    @Override public View onCreateInputView() {
        // load preferences
    
        return mInputView;
    }
    
    
    @Override public void onStartInputView(EditorInfo attribute, boolean restarting) {
        super.onStartInputView(attribute, restarting);
    
        setInputView(onCreateInputView());
    
        ...
    }