working of OnConfigurationChanged() in MonoDroid
-
29-04-2021 - |
Question
I'm new to android development and I've been working on android through java(eclipse) till now but now I'm switching to Mono for Android
which uses C#.
In java on orientation changed, I've used following code snippet :
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else{
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}
}
When trying to do the same in C# in Mono for Android
, I tried this
public override void OnConfigurationChanged(Android.Content.Res.Configuration newConfig)
{
base.OnConfigurationChanged (newConfig);
if (newConfig.Orientation == Android.Content.Res.Configuration.ORIENTATION_LANDSCAPE)
{
Toast.MakeText(this, "landscape",ToastLength.Long).Show();
}
else /* if (orientation == 0) */
{
Toast.MakeText(this, "portrait", ToastLength.Long).Show();
}
}
but Android.Content.Res.Configuration
doesn't have any attribute with value 'ORIENTATION_LANDSCAPE` when I try to use following statement
if (newConfig.Orientation == Android.Content.Res.Configuration.ORIENTATION_LANDSCAPE)
What might be the solution? Any other option available?
Any help appreciated !
La solution
You must use:
Android.Content.Res.Orientation.Landscape
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow