在 xamarin android 应用程序中更改显示语言 [英] Change display language within an xamarin android app

查看:33
本文介绍了在 xamarin android 应用程序中更改显示语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改应用内的显示语言?我希望不同文化的用户可以使用一台扫描仪工作,而不会改变设备的全球文化.

How can I change the display language within an app? I want that users with different cultures can work with one scanner without changing the global culture of the device.

我有一个带有点击事件的语言按钮,我在其中调用了一个方法:

I have a laguage button with a click event in wich I call a method:

public void SetLocale(string language = "")
{
    Locale locale = String.IsNullOrEmpty(language)
                               ? new Locale("de-DE")
                               : new Locale(language);
    Locale.Default = locale;
    var config = new global::Android.Content.Res.Configuration();
    config.Locale = locale;
    var context = global::Android.App.Application.Context;
    context.Resources.UpdateConfiguration(config, context.Resources.DisplayMetrics);
}

但不幸的是,当我按下按钮时没有任何反应.

But unfortunately nothing happens when I press the button.

点击事件为:

_btnen.Click += delegate
{
    SetLocale("en-GB");
};

推荐答案

What can work for You,如果上下文可以被遗忘(所有属性值都可以丢失),你可以只强制Activity 重绘自身.

What can work for You, if the context can be forgotten (all property values can be lost), You can just force the Activity to redraw itself.

btn.Click += delegate
{
    SetLocale("en-GB");

    this.Recreate(); //this line
}

这篇关于在 xamarin android 应用程序中更改显示语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆