Android配置文件,我可以访问它以在启动时检测fontScale吗?
我知道我可以覆盖OnConfigurationChanged()以检测fontScale何时发生更改。但是,我想在启动时知道配置文件是否可供MainActivity访问,以查看运行时fontScale是否设置为正常值以外的值,例如1.15(大) Android配置文件,我可以访问它以在启动时检测fontScale吗 答案是肯定的,您可以将Android配置文件,我可以访问它以在启动时检测fontScale吗?,android,xamarin.forms,Android,Xamarin.forms,我知道我可以覆盖OnConfigurationChanged()以检测fontScale何时发生更改。但是,我想在启动时知道配置文件是否可供MainActivity访问,以查看运行时fontScale是否设置为正常值以外的值,例如1.15(大) Android配置文件,我可以访问它以在启动时检测fontScale吗 答案是肯定的,您可以将FontScale更改为正常值以外的值。例如,在应用程序启动时更改FontScale: protected override void OnCreate(Bun
FontScale
更改为正常值以外的值。例如,在应用程序启动时更改FontScale
:
protected override void OnCreate(Bundle bundle)
{
initFontScale();
base.OnCreate(bundle);
...
}
private void initFontScale()
{
Configuration configuration = Resources.Configuration;
configuration.FontScale = (float)1.45;
//0.85, 1 standard, 1.15 bigger, 1.3, 1.45
DisplayMetrics metrics = new DisplayMetrics();
WindowManager.DefaultDisplay.GetMetrics(metrics);
metrics.ScaledDensity = configuration.FontScale * metrics.Density;
// DEPRECATED BaseContext.Resources.UpdateConfiguration(configuration, metrics);
// Beter use:
BaseContext.ApplicationContext.CreateConfigurationContext(configuration);
BaseContext.Resources.DisplayMetrics.SetTo(metrics);
}
你需要在应用程序启动时更改
fontScale
吗?不,我只想知道fontScale是什么,这样我就可以确定UI的其他方面,这正是我想要的!非常感谢您对@FullEnglish的帮助,如果这对您有帮助,请将其标记为答案。:)所有这些都完成了,我必须参考帮助,了解如何接受答案哈哈。一开始并不明显:)@FullEnglish,happy coding.)@YorkShen MSFT我同意,这正是我想要的。快速提问,intellisense表示Resources.UpdateConfiguration已弃用(过时)。代码仍然有效,但是想知道更新后的方法是什么吗?如果他们更新了什么。