MonoDroid 中 OnConfigurationChanged() 的工作原理
我是 Android 开发新手,到目前为止我一直在通过 java(eclipse) 开发 Android,但现在我正在切换到使用 C# 的 Mono for Android
。
在java中,方向改变时,我使用了以下代码片段:
@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();
}
}
当尝试在Mono for Android
中的C#中执行相同操作时,我尝试了这个
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();
}
}
但是Android.Content.Res。当我尝试使用以下语句时,配置
没有任何值为“ORIENTATION_LANDSCAPE”的属性
if (newConfig.Orientation == Android.Content.Res.Configuration.ORIENTATION_LANDSCAPE)
解决方案可能是什么?还有其他选择吗?
任何帮助表示赞赏!
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 !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用:
API 参考 - 枚举
API 参考 - 配置
You must use:
API reference - enum
API refenence - Configuration