本文介绍了在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应用程序中更改显示语言
发布评论