简体   繁体   English

如何在Android键盘(IME)中处理配置更改?

[英]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. 我一直在关注随文档提供的Android示例来设计新的(相对简单的)键盘。 At this point I am stuck with configuration change (like theme, textSize or bit complex stuff) which requires IME to recreate itself. 在这一点上,我坚持配置更改(如主题,textSize或位复杂的东西),这需要IME重新创建自己。

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. StopService值返回true但没有效果。

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: 解:

@Override public View onCreateInputView() {
    // load preferences

    return mInputView;
}


@Override public void onStartInputView(EditorInfo attribute, boolean restarting) {
    super.onStartInputView(attribute, restarting);

    setInputView(onCreateInputView());

    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM