假设我想根据选择的子类型更改布局,但我无法这样做.
到目前为止,我已经为英语(GB)创建了另一个xml文件,我称之为qwerty_gb.xml(为了测试,我已经交换了Return和Del键)
然后宣布私有
LatinKeyboard mQwertyKeyboardGB;
并将其与Softkeyboard.java的onInitializeInterface重写方法中的默认键盘一起初始化
像这样:
mQwertyKeyboardGB = new LatinKeyboard(this,R.xml.qwerty_gb);
我不知道我在这里错过了什么.
解决方法 编辑SoftKeyboard.java文件并进行以下修改,以便为每个子类型设置特定的布局.1-首先参考布局.
mQwertyKeyboard = new LatinKeyboard(this,R.xml.qwerty);mPersianKeyboard = new LatinKeyboard(this,R.xml.persian);
2-在OnCreateinputVIEw中添加以下内容以应用正确的布局.
inputMethodSubtype subtype = minputMethodManager.getCurrentinputMethodSubtype();switch(subtype.getLocale()) { case "fa_IR": setLatinKeyboard(mPersianKeyboard); break; case "en_US": setLatinKeyboard(mQwertyKeyboard); break;}
如果语言环境是fa_IR,则上面的代码应用mPersianKeyboard.语言环境fa_IR在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-最后将`onCurrentinputMethodSubtypeChanged方法修改为以下内容:
@OverrIDepublic voID onCurrentinputMethodSubtypeChanged(inputMethodSubtype subtype) { minputVIEw.setSubtypeOnSpaceKey(subtype); switch(subtype.getLocale()) { case "fa_IR": setLatinKeyboard(mSymbolsKeyboard); break; case "en_US": setLatinKeyboard(mQwertyKeyboard); break; };}
注意:在API级别24中不推荐使用getLocale()方法.请改用getLanguageTag().更好的方法是检查版本并使用正确的方法来获得正确的版本.
总结以上是内存溢出为你收集整理的如何为android中的子类型加载不同的键盘布局?全部内容,希望文章能够帮你解决如何为android中的子类型加载不同的键盘布局?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)