Android鍵盤輸入語言設(shè)置默認打開myanmar緬甸語的步驟
更新時間:2013年06月17日 15:56:56 作者:
如何實現(xiàn)Android鍵盤輸入語言默認打開為myanmar緬甸語,如果要設(shè)置某種語言在輸入法默認打開可按一下步驟添加文件,我這里已經(jīng)驗證時OK的
locale是通過系統(tǒng)設(shè)置的地區(qū)和latin輸入法語言通過merger出來的,所以在系統(tǒng)地區(qū)設(shè)置和輸入法語言中同時支持才可以在“輸入語言設(shè)置“里設(shè)置
languageList是從存儲latin輸入法設(shè)置的latin_preferences.xml文件里讀取出來的,上一次設(shè)置的輸入語言
如果要設(shè)置某種語言在輸入法默認打開可按一下步驟添加文件,我這里已經(jīng)驗證時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" />權(quán)限
<receiver android:name="LatinImeReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
languageList是從存儲latin輸入法設(shè)置的latin_preferences.xml文件里讀取出來的,上一次設(shè)置的輸入語言
如果要設(shè)置某種語言在輸入法默認打開可按一下步驟添加文件,我這里已經(jīng)驗證時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" />權(quán)限
復制代碼 代碼如下:
<receiver android:name="LatinImeReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
相關(guān)文章
Android 8.1 Launcher3實現(xiàn)動態(tài)指針時鐘功能
這篇文章主要介紹了Android 8.1 Launcher3實現(xiàn)動態(tài)指針時鐘功能,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2018-07-07
Android 開發(fā)仿簡書登錄框可刪除內(nèi)容或顯示密碼框的內(nèi)容
本文通過實例代碼給大家分享android開發(fā)中模仿簡書登錄框可刪除內(nèi)容或顯示密碼框的內(nèi)容,非常不錯,具有參考借鑒價值,需要的朋友參考下吧2016-12-12
Android自定義View實現(xiàn)九宮格圖形解鎖(Kotlin版)
這篇文章主要為大家詳細介紹了Android自定義View實現(xiàn)九宮格圖形解鎖,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-09-09
Android利用爬蟲實現(xiàn)模擬登錄的實現(xiàn)實例
這篇文章主要介紹了Android利用爬蟲實現(xiàn)模擬登錄的實現(xiàn)實例的相關(guān)資料,希望通過本文能幫助到大家實現(xiàn)這樣的功能,需要的朋友可以參考下2017-09-09
Android開發(fā) Activity和Fragment詳解
本文主要介紹Android開發(fā) Activity和Fragment,這里對Activity和Fragment的知識做了詳細講解,并附簡單代碼示例,有興趣的小伙伴可以參考下2016-08-08
加載頁面遮擋耗時操作任務(wù)頁面--第三方開源之AndroidProgressLayout
AndroidProgressLayout實現(xiàn)為界面添加圓形進度條。調(diào)用setprogress()方法顯示和隱藏進度條,這篇文章主要介紹了加載頁面遮擋耗時操作任務(wù)頁面--第三方開源之AndroidProgressLayout的相關(guān)資料,需要的朋友可以參考下2015-11-11
簡單實現(xiàn)Android學生管理系統(tǒng)(附源碼)
這篇文章主要介紹了如何簡單實現(xiàn)Android學生管理系統(tǒng),特別適合計算機專業(yè)的即將畢業(yè)的同學學習借鑒制作學生管理系統(tǒng),感興趣的小伙伴們可以參考一下2015-12-12

