Edit the SoftKeyboard.java file with following modifications in order to have specific layout for each subtype.
1- Reference your layouts first.
mQwertyKeyboard = new LatinKeyboard(this, R.xml.qwerty); mPersianKeyboard = new LatinKeyboard(this, R.xml.persian);
2- In the OnCreateInputView add the following to apply the right layout.
InputMethodSubtype subtype = mInputMethodManager.getCurrentInputMethodSubtype(); switch(subtype.getLocale()) { case "fa_IR": setLatinKeyboard(mPersianKeyboard); break; case "en_US": setLatinKeyboard(mQwertyKeyboard); break; }
The above code applies mPersianKeyboard if the locale is fa_IR. The locale fa_IR is set in the method.xml.
<subtype android:label="@string/label_subtype_generic" android:icon="@drawable/icon_en_us" android:imeSubtypeLocale="en_US" android:imeSubtypeMode="keyboard" /> <subtype android:label="@string/label_subtype_generic" android:icon="@drawable/icon_en_gb" android:imeSubtypeLocale="fa_IR" android:imeSubtypeMode="keyboard" />
3- And finally modify `onCurrentInputMethodSubtypeChanged method to the following:
@Override public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) { mInputView.setSubtypeOnSpaceKey(subtype); switch(subtype.getLocale()) { case "fa_IR": setLatinKeyboard(mSymbolsKeyboard); break; case "en_US": setLatinKeyboard(mQwertyKeyboard); break; }; }
Note: The getLocale() method was deprecated in API level 24. Use getLanguageTag() instead. The better is to check the version and use the right method for the right version.