EDIT 2

EDIT
Override attachBaseContext method to update the context in activity
protected override void AttachBaseContext(Context @base)
{
base.AttachBaseContext(@base);
}
end edit
In Android API 25 Resources.UpdateConfiguration(Configuration, DisplayMetrics) was deprecated and it's advised to use Context context = CreateConfigurationContext(Configuration); instead.
Current implementation
public override Resources Resources
{
get
{
Resources res = base.Resources;
Configuration config = new Configuration();
config.SetToDefaults();
res.UpdateConfiguration(config, res.DisplayMetrics);
return res;
}
}
Referencing Android context.getResources.updateConfiguration() deprecated as a guide, tried the following:
public override Resources Resources
{
get
{
Configuration overrideConfiguration = base.Resources.Configuration;
overrideConfiguration.SetToDefaults();
Context context = CreateConfigurationContext(overrideConfiguration);
Resources res = context.Resources;
return res;
}
}
However this produces anomalous errors..
Android.Views.InflateException: Error inflating class
com.android.internal.widget.DialogTitle
How to correctly implement Context context = CreateConfigurationContext(Configuration)?
Note 'Current implementation' works perfectly fine but as encouraged to not use deprecated code want to the replacement working
Not sure if it's your need,you could change the attachBaseContext method like this,it could work:
protected override void AttachBaseContext(Context @base)
{
Configuration overrideConfiguration = new Configuration();
overrideConfiguration = @base.Resources.Configuration;
overrideConfiguration.SetToDefaults();
Context context = @base.CreateConfigurationContext(overrideConfiguration);
base.AttachBaseContext(context);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With