尝试本地化我的应用程序,但该应用程序未本地化(动态地甚至从应用程序本地化)
我尝试创建一个语言环境帮助器类,我还创建了3个字符串文件 AR zh(默认) fr 但ar或fr均不起作用
import android.content.Context;
import android.content.res.Resources;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import java.util.Locale;
public class LocaleHelper {
public static void setDefaultLocale(Context context) {
SharakehSharedPreference sharakehSharedPreference = new SharakehSharedPreference(context);
Locale locale;
if (null == sharakehSharedPreference.getKey("locale")) {
sharakehSharedPreference.setKey("locale", "en");
}
if (sharakehSharedPreference.getKey("locale").equalsIgnoreCase("en"))
locale = new Locale("ar");
else locale = new Locale("en");
sharakehSharedPreference.setKey("locale", locale.toString());
locale.setDefault(locale);
Resources res = context.getResources();
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.setLocale(locale);
res.updateConfiguration(conf, dm);
}
}