4

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..?

1 Answer 1

12

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()); } 
Sign up to request clarification or add additional context in comments.

2 Comments

How can I handle click events of my custom layouts.
This method of recreating entire input view is especially good because KeyboardView incorrectly caches keyWidth which makes switching layout with simple setKeyboard impossible.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.