java - 应用程序内的区域设置更改不起作用

标签 java android locale

我正在尝试更改应用程序的语言,但它没有发生。我已经尝试了几乎所有可用的解决方案,但没有一个有效。有趣的是,大多数代码都能够更改 Facebook Account Kit Activity 的语言,但其他 Activity 的语言没有更改。下面是我的应用程序类和 list 文件。

public class MyApplication extends Application {


    private Locale locale = null;

    @Override
    public void onConfigurationChanged(Configuration newConfig)
    {
        super.onConfigurationChanged(newConfig);
        if (locale != null)
        {
            newConfig.locale = locale;
            Locale.setDefault(locale);
            getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
        }
    }

    @Override
    public void onCreate()
    {
        super.onCreate();
        Configuration config = getBaseContext().getResources().getConfiguration();

        new SharedPrefManager(this).setLanguage("fr");
        String lang = new SharedPrefManager(this).getLanguage();

        locale = new Locale(lang);
        Locale.setDefault(locale);
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
        AccountKit.initialize(getApplicationContext());
    }


}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.pullerr.pullerrdriver">
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
    <uses-permission android:name="android.permission.CHANGE_CONFIGURATION"/>
    <application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data android:name="com.facebook.accountkit.ApplicationName"
            android:value="@string/app_name" />
        <meta-data android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/FACEBOOK_APP_ID" />
        <meta-data android:name="com.facebook.accountkit.ClientToken"
            android:value="@string/ACCOUNT_KIT_CLIENT_TOKEN" />
        <meta-data android:name="com.facebook.accountkit.FacebookAppEventsEnabled"
            android:value="false"/>

        <activity
            android:name="com.facebook.accountkit.ui.AccountKitActivity"
            android:theme="@style/AppLoginTheme"
            tools:replace="android:theme"/>
        <activity
            android:configChanges="layoutDirection|locale"
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAINACTIVITY" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:configChanges="layoutDirection|locale"
            android:name=".LoadDetails"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.LOADDETAILS" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:configChanges="layoutDirection|locale"
            android:name=".Login"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:configChanges="layoutDirection|locale"
            android:name=".Register"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.REGISTER" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <service android:name="services.LocationService"/>
    </application>

</manifest>

Facebook AccountKit Language is Changed

最佳答案

关于java - 应用程序内的区域设置更改不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46189827/

相关文章:

java - Maven svn : E215004: Authentication failed and interactive prompting is disabled; see the --force-interactive option

java - 在抽屉导航项目单击上切换 fragment

具有应用内区域设置更改的 Android App Bundle

java - 如何从 HttpServletRequest 获取客户端在 java 中的时区?

java - java中如何将html编码的字符串转换为Unicode

Java 在对象或变量上同步?

android - Android 上基于枚举的单例的生命周期

android - 通过 Asmack 发送图像时创建消息

android - 适用于 iOS 和 Android 的网络延迟、电池和负载模拟工具

当语言环境不是英语时,Kotlin 崩溃