<?xml version="1.0" encoding="utf-8"?> <android.inputmethodservice.KeyboardView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/keyboard" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:keyPreviewHeight="35dp" android:keyPreviewLayout="@layout/preview" />
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:background="@color/key_preview_background" android:textColor="@color/key_preview_text_color" android:textStyle="bold" android:textSize="25sp" />
<?xml version="1.0" encoding="utf-8"?> <Keyboard xmlns:android="http://schemas.android.com/apk/res/android" android:keyWidth="7.5%p" android:horizontalGap="5px" android:verticalGap="0px" android:keyHeight="40dp"> <Row> <Key android:codes="-1" android:keyIcon="@drawable/ic_keyboard_capslock_white_24dp" android:keyWidth="13%p" android:keyEdgeFlags="left" /> <Key android:codes="1103" android:keyLabel="" /> <Key android:codes="1095" android:keyLabel="" /> <Key android:codes="1089" android:keyLabel="" /> <Key android:codes="1084" android:keyLabel="" /> <Key android:codes="1080" android:keyLabel="" /> <Key android:codes="1090" android:keyLabel="" /> <Key android:codes="1100" android:keyLabel="" /> <Key android:codes="1073" android:keyLabel="" /> <Key android:codes="1102" android:keyLabel="" /> <Key android:codes="-5" android:keyIcon="@drawable/ic_backspace_white_24dp" android:isRepeatable="true" android:keyEdgeFlags="right" android:keyWidth="13%p" /> </Row> </Keyboard>
<?xml version="1.0" encoding="utf-8"?> <input-method xmlns:android="http://schemas.android.com/apk/res/android"> <subtype android:label="@string/subtype_en_US" android:imeSubtypeLocale="en_US" android:imeSubtypeMode="keyboard" /> <subtype android:label="@string/subtype_ru_RU" android:imeSubtypeLocale="ru_RU" android:imeSubtypeMode="keyboard" /> </input-method>
@Override public View onCreateInputView() { mKeyboardView = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard, null); mKeyboard = new Keyboard(this, R.xml.keys_definition_ru); mKeyboard.setShifted(isCapsOn); // , mKeyboardView.setKeyboard(mKeyboard); mKeyboardView.setOnKeyboardActionListener(this); return mKeyboardView; } @Override public void onKey(int primaryCode, int[] ints) { Log.d(TAG, "onKey " + primaryCode); InputConnection ic = getCurrentInputConnection(); playClick(primaryCode); switch (primaryCode) { case Keyboard.KEYCODE_DELETE: ic.deleteSurroundingText(1, 0); break; case Keyboard.KEYCODE_SHIFT: handleShift(); break; case Keyboard.KEYCODE_DONE: ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER)); break; case Keyboard.KEYCODE_ALT: handleSymbolsSwitch(); break; case Keyboard.KEYCODE_MODE_CHANGE: handleLanguageSwitch(); break; default: char code = (char) primaryCode; if (Character.isLetter(code) && isCapsOn) { code = Character.toUpperCase(code); } ic.commitText(String.valueOf(code), 1); break; } }
<service android:name=".SimpleIME" android:label="@string/simple_ime" android:permission="android.permission.BIND_INPUT_METHOD"> <meta-data android:name="android.view.im" android:resource="@xml/method" /> <intent-filter> <action android:name="android.view.InputMethod" /> </intent-filter> </service>
Source: https://habr.com/ru/post/322070/
All Articles