安卓配置文件,我可以在启动时访问它以检测字体缩放吗?



我知道我可以覆盖OnConfigurationChanged((以检测字体规模何时更改,但是,我想在启动时知道配置文件是否可供MainActivity访问以查看在运行时字体缩放是否设置为正常值以外的值,例如1.15(大(

安卓配置文件,我可以访问它以在启动时检测字体缩放吗?

答案是肯定的,您可以将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);
}

最新更新