Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Layout of Keyboard Dynamically

I am working on create custom keyboard. I got such a good and useful demo for that from Here. I want to create multiple theme of keyboard, so i create another layout for keyboard, but now problem is i don't know how to set the layout of current keyboard or have to load keyboard newly or have to do something else.. to change the design of keyboard don't have any Idea.

My concept is user have to choose the keyboard theme from activity and the keyboard design will change.

Can anybody help me or have any idea to push this problem out..?

like image 246
Yog Guru Avatar asked Jan 07 '13 05:01

Yog Guru


1 Answers

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());
}
like image 50
Yog Guru Avatar answered Sep 30 '22 05:09

Yog Guru