アプリの言語をアプリ設定から変更するにはどうすればよいですか?アプリケーション言語を変更するにはどうすればよいですか?
私のアプリがスペイン語、ポルトガル語、英語の3言語をサポートし、私のアプリの設定メニューから言語を選択するオプションを提供します。
アプリの言語をアプリ設定から変更するにはどうすればよいですか?アプリケーション言語を変更するにはどうすればよいですか?
私のアプリがスペイン語、ポルトガル語、英語の3言語をサポートし、私のアプリの設定メニューから言語を選択するオプションを提供します。
次のクラスを使用すると、アプリケーションから言語を変更できます。
public class LocaleHelper {
private static final String SELECTED_LANGUAGE = "Locale.Helper.Selected.Language";
public static void onCreate(Context context) {
String lang = getPersistedData(context, Locale.getDefault().getLanguage());
setLocale(context, lang);
}
public static void onCreate(Context context, String defaultLanguage) {
String lang = getPersistedData(context, defaultLanguage);
setLocale(context, lang);
}
public static String getLanguage(Context context) {
return getPersistedData(context, Locale.getDefault().getLanguage());
}
public static void setLocale(Context context, String language) {
persist(context, language);
updateResources(context, language);
}
private static String getPersistedData(Context context, String defaultLanguage) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
return preferences.getString(SELECTED_LANGUAGE, defaultLanguage);
}
private static void persist(Context context, String language) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = preferences.edit();
editor.putString(SELECTED_LANGUAGE, language);
editor.apply();
}
private static void updateResources(Context context, String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
Resources resources = context.getResources();
android.content.res.Configuration configuration = resources.getConfiguration();
configuration.locale = locale;
DisplayMetrics dm = resources.getDisplayMetrics();
resources.updateConfiguration(configuration, dm);
}
}
以下のオブジェクトを使用した呼び出し言語の変更。
LocaleHelper.setLocale(getBaseContext(), "ar");
これを呼び出した後、現在のアクティビティを更新するのを忘れないでください。これがあなたを助けることを願っています。
実装ローカライズは
言語ごとに別々の値のフォルダを作成し、アンドロイドOSが自動的に
はステップhere
に従ってくださいウルデバイス上のロケールに基づいて対応する値を選択しますあなたのソリューションですhttp://www.compiletimeerror.com/2014/10/android-localization-tutorial-with.html?m=1
https://www.tutorialspoint.com/android/android_localization.htm
アクションバーのタイトル[多言語アンドロイドアプリケーションを作成](http://stackoverflow.com/questions/39727543/make-multi-language-android-application/40302562#40302562) –