Well, you might have seen few questions like asking for this. But reading all of those questions/answers and almost all of the android inputmethod webpages in Google, I am still in trouble.
My final goal is to create a custom keyboard. But of course, mine will have special input methods for certain language.
But this time, all I want is to show my custom view when the keyboard is popped up. I've managed to pop the default layout based on a qwerty.xml file, which is something like this.
xml/qwerty.xml
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="10%p"
android:horizontalGap="0px"
android:verticalGap="0px"
android:keyHeight="60dp"
>
<Row android:rowEdgeFlags="bottom">
<Key android:codes="999" android:keyLabel="Settings" android:keyWidth="20%" android:keyEdgeFlags="left"/>
<Key android:codes="44" android:keyLabel="," android:keyWidth="7%p" />
<Key android:codes="47" android:keyLabel="/" android:keyWidth="7%p" />
<Key android:codes="32" android:keyLabel="SPACE" android:keyWidth="30%p" android:isRepeatable="true"/>
<Key android:codes="-5" android:keyLabel="DEL" android:keyWidth="18%p" android:isRepeatable="true"/>
<Key android:codes="-4" android:keyLabel="DONE" android:keyWidth="18%p" android:keyEdgeFlags="right"/>
</Row>
And in my class which extends InputMethodService, i have this code which creates input view.
private KeyboardView myKeyView;
private Keyboard keyboard;
@Override
public View onCreateInputView() {
myKeyView = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard, null);
keyboard = new Keyboard(this, R.xml.qwerty);
myKeyView.setKeyboard(keyboard);
myKeyView.setOnKeyboardActionListener(this);
return myKeyView;
}
and of course, because I had problems on applying my custom view to my source. I just made some effort on the other side. When Settings key in xml is pressed,
<Key android:codes="999" android:keyLabel="Settings" android:keyWidth="20%" android:keyEdgeFlags="left"/>
it will call SettingsActivity
@Override
public void onKey(int primaryCode, int[] keyCodes) {
if(primaryCode == 999) {
openSettings();
}
}
public void openSettings()
{
Intent intent = new Intent(this, WRKeySettings.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
It works nicely until here, but I am in to this view problem.
What I think from reading android develpers and some of the articles is that, I could extend KeyboardView to make my custom view and in this method, I might be able to draw keys somehow with onDraw(). But I am having so much trouble on doing this.
Any suggestions will pleased. Thanks.