How to change background color or theme of keys dynamically in Custom Keyboard Android

后端 未结 2 973
栀梦
栀梦 2021-01-06 16:04

I am working on Custom keyboard app I need to set or change background theme or color of keyboard .their setting.xml view in my app where user can select different backgrou

2条回答
  •  隐瞒了意图╮
    2021-01-06 16:29

    Get solution to change the layout of custom keyboard.

    When keyboard first time load onCreateInputView() is called. After that when keyboard open onStartInputView(EditorInfo attribute, boolean restarting) called every time.

    So, now layout of keyboard(Theme) have to define in onCreateInputView() Like This

    public KeyboardView mInputView;
    public View onCreateInputView() {
    
        SharedPreferences pre = getSharedPreferences("test", 1);
        int theme = pre.getInt("theme", 1);
    
        if(theme == 1)
        {
            this.mInputView = (KeyboardView) this.getLayoutInflater().inflate(R.layout.input, null);
        }else
        {
            this.mInputView = (KeyboardView) this.getLayoutInflater().inflate(R.layout.input_2, null);
    
        }
        this.mInputView.setOnKeyboardActionListener(this);
        this.mInputView.setKeyboard(this.mQwertyKeyboard);
        return this.mInputView;
    }
    

    and do this in onStartInputView

    public void onStartInputView(EditorInfo attribute, boolean restarting) {
        super.onStartInputView(attribute, restarting);
    
        setInputView(onCreateInputView());
    }
    

提交回复
热议问题