Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android鍵盤輸入語言設置默認打開myanmar緬甸語的步驟

Android鍵盤輸入語言設置默認打開myanmar緬甸語的步驟

編輯:關於Android編程

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>
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved