本文介绍了使用xamarin和C#在android上更改cultureinfo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用一个自定义方法来将当前的Cultureinfo动态切换为法语 fr

Im calling a custom method to dynamically switch the current cultureinfo to french "fr"

与此类似,但是在调用该方法后,我的android应用仍使用默认的区域性是 en,但是在调试模式下,这种文化似乎还可以。我的文件夹还可以。我同时拥有和配置字符串值。文件夹:resource / values / strings.xml,resource / values-fr / strings.xml。

Like this but after calling that method my android app still use the default culture which is 'en' but in debug mode the culture seems to be ok. My folder are ok. I have both and the string values are configured. folder: resource/values/strings.xml, resource/values-fr/strings.xml.

我是否需要重新加载contentview或其他内容?我在这里想念什么?

Do I need to reload my contentview or something? what do I miss here?

    private void SetLocal(string lang) 
    {
        System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(lang);
        System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);
    }


推荐答案

我知道来晚了回答这个问题,但我找到了解决方案!
尝试使用它对我有用:

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);  

这篇关于使用xamarin和C#在android上更改cultureinfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 23:29