Android键盘输入语言设置默认打开myanmar缅甸语的步骤
更新时间:2013年06月17日 15:56:56 作者:
如何实现Android键盘输入语言默认打开为myanmar缅甸语,如果要设置某种语言在输入法默认打开可按一下步骤添加文件,我这里已经验证时OK的
locale是通过系统设置的地区和latin输入法语言通过merger出来的,所以在系统地区设置和输入法语言中同时支持才可以在“输入语言设置“里设置
languageList是从存储latin输入法设置的latin_preferences.xml文件里读取出来的,上一次设置的输入语言
如果要设置某种语言在输入法默认打开可按一下步骤添加文件,我这里已经验证时OK的,你可以试一下。
提供简单的sample code,如默认将缅甸语、英文、法语输入法勾选:
1.书写文件LatinImeReceiver.java
package com.android.inputmethod.latin;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.util.Log;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
//import android.view.inputmethod.InputMethodSubtype;
import android.text.TextUtils;
public class LatinImeReceiver extends BroadcastReceiver {
private static final String TAG = LatinImeReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
Log.d("LatinImeReceiver", "step1");
SharedPreferences sp = context.getSharedPreferences("com.android.inputmethod.latin_preferences",
Context.MODE_PRIVATE);
boolean hasSet = sp.getBoolean("has_set", false);
if (!hasSet) {
Log.d("LatinImeReceiver", "step2");
Editor editor = sp.edit();
Log.d("LatinImeReceiver", "step3");
editor.putString(LatinIME.PREF_SELECTED_LANGUAGES, "en_US,my,fr"); //默认将英语、缅甸语勾选,具体该怎么写可以参考inputlanguageselection.java中的WHITELIST_LANGUAGES
editor.putBoolean("has_set", true);
Log.d("LatinImeReceiver", "step4");
//editor.commit();
SharedPreferencesCompat.apply(editor);
Log.d("LatinImeReceiver", "step5");
}
}
将其放置到路径packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin文件夹下面
2.注册intent,在packages/inputmethods/LatinIME/java/androidManifest.xml中的最后面加入:
并增加 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />权限
<receiver android:name="LatinImeReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
languageList是从存储latin输入法设置的latin_preferences.xml文件里读取出来的,上一次设置的输入语言
如果要设置某种语言在输入法默认打开可按一下步骤添加文件,我这里已经验证时OK的,你可以试一下。
提供简单的sample code,如默认将缅甸语、英文、法语输入法勾选:
1.书写文件LatinImeReceiver.java
复制代码 代码如下:
package com.android.inputmethod.latin;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.util.Log;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
//import android.view.inputmethod.InputMethodSubtype;
import android.text.TextUtils;
public class LatinImeReceiver extends BroadcastReceiver {
private static final String TAG = LatinImeReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
Log.d("LatinImeReceiver", "step1");
SharedPreferences sp = context.getSharedPreferences("com.android.inputmethod.latin_preferences",
Context.MODE_PRIVATE);
boolean hasSet = sp.getBoolean("has_set", false);
if (!hasSet) {
Log.d("LatinImeReceiver", "step2");
Editor editor = sp.edit();
Log.d("LatinImeReceiver", "step3");
editor.putString(LatinIME.PREF_SELECTED_LANGUAGES, "en_US,my,fr"); //默认将英语、缅甸语勾选,具体该怎么写可以参考inputlanguageselection.java中的WHITELIST_LANGUAGES
editor.putBoolean("has_set", true);
Log.d("LatinImeReceiver", "step4");
//editor.commit();
SharedPreferencesCompat.apply(editor);
Log.d("LatinImeReceiver", "step5");
}
}
将其放置到路径packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin文件夹下面
2.注册intent,在packages/inputmethods/LatinIME/java/androidManifest.xml中的最后面加入:
并增加 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />权限
复制代码 代码如下:
<receiver android:name="LatinImeReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
相关文章
Android 8.1 Launcher3实现动态指针时钟功能
这篇文章主要介绍了Android 8.1 Launcher3实现动态指针时钟功能,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下2018-07-07
Android 开发仿简书登录框可删除内容或显示密码框的内容
本文通过实例代码给大家分享android开发中模仿简书登录框可删除内容或显示密码框的内容,非常不错,具有参考借鉴价值,需要的朋友参考下吧2016-12-12
Android自定义View实现九宫格图形解锁(Kotlin版)
这篇文章主要为大家详细介绍了Android自定义View实现九宫格图形解锁,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2021-09-09
加载页面遮挡耗时操作任务页面--第三方开源之AndroidProgressLayout
AndroidProgressLayout实现为界面添加圆形进度条。调用setprogress()方法显示和隐藏进度条,这篇文章主要介绍了加载页面遮挡耗时操作任务页面--第三方开源之AndroidProgressLayout的相关资料,需要的朋友可以参考下2015-11-11


最新评论