在Xamarin Android应用程序中更改显示语言

编程入门 行业动态 更新时间:2024-10-27 04:29:40
本文介绍了在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.

我有一个带有单击事件的laguage按钮,在调用方法的过程中:

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

推荐答案

什么可以为您工作,如果可以忘记上下文(所有属性值都可以丢失),则可以强制执行 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应用程序中更改显示语言

本文发布于:2023-10-07 01:29:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1468056.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   语言   Xamarin   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!