changing cultureinfo on android using xamarin and c#

一个人想着一个人 提交于 2019-12-04 19:17:48

I know it's a bit late to answer this question but I found the solution!! Try this it works for me:

 string cultureName = "fr-FR";
        var locale = new Java.Util.Locale(cultureName);
        Java.Util.Locale.Default = locale;

        var config = new Android.Content.Res.Configuration { Locale = locale };
        BaseContext.Resources.UpdateConfiguration(config, BaseContext.Resources.DisplayMetrics);  

I can't test it right now, but try this:

        Resources.Configuration.Locale = new Locale(lang);
        Resources.UpdateConfiguration(Resources.Configuration, Resources.DisplayMetrics);
Edgar David

All this in the MainActivity

using System.Threading;
using System.Globalization;

void SetLocale() {

    CultureInfo ci = new CultureInfo("es-US");

    Thread.CurrentThread.CurrentCulture = ci;
    Thread.CurrentThread.CurrentUICulture = ci;

    Console.WriteLine("CurrentCulture set: " + ci.Name);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!