Xamarin:在屏幕旋转时,OptionMenu 图标重复两次
Xamarin : On screen rotation the OptionMenu Icon is repeated twice
我正在使用 MenuInflater
放在导航栏上的选项菜单
在创建 activity 之后,当我尝试旋转屏幕时,我看到了两个图标,而不是一个图标。
我正在寻找关于如何处理屏幕旋转事件的解决方案。
这里是 activity.cs
[Activity(Label = "Menu", Icon = "@drawable/Icon", ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
public class MenuNavigation : ListActivity {
string[] items;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
items = new string[] { "Chat", "News", "Events", "Member List", "My Profile", "About Association" ,"About Application"};
ListAdapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleListItem1, items);
}
public override bool OnPrepareOptionsMenu(IMenu menu)
{
MenuInflater.Inflate(Resource.Menu.main, menu);
return base.OnPrepareOptionsMenu(menu);
}
}
和menu/main.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_logout"
android:icon="@drawable/logout"
android:orderInCategory="100"
android:title="Log Out"
android:showAsAction="ifRoom"/>
</menu>
当我在 developer.xamarin 上搜索解决方案时 -> Handling Rotation
我找到了我自己的问题的解决方案。
我所要做的就是:
[Activity(Label = "Menu", Icon = "@drawable/Icon", ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
配置更改 = Android.Content.PM.ConfigChanges.Orientation
这已经解决了问题,但我认为可能有更好的解决方案,因此欢迎任何其他解决方案。
我正在使用 MenuInflater
放在导航栏上的选项菜单在创建 activity 之后,当我尝试旋转屏幕时,我看到了两个图标,而不是一个图标。
我正在寻找关于如何处理屏幕旋转事件的解决方案。
这里是 activity.cs
[Activity(Label = "Menu", Icon = "@drawable/Icon", ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
public class MenuNavigation : ListActivity {
string[] items;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
items = new string[] { "Chat", "News", "Events", "Member List", "My Profile", "About Association" ,"About Application"};
ListAdapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleListItem1, items);
}
public override bool OnPrepareOptionsMenu(IMenu menu)
{
MenuInflater.Inflate(Resource.Menu.main, menu);
return base.OnPrepareOptionsMenu(menu);
}
}
和menu/main.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_logout"
android:icon="@drawable/logout"
android:orderInCategory="100"
android:title="Log Out"
android:showAsAction="ifRoom"/>
</menu>
当我在 developer.xamarin 上搜索解决方案时 -> Handling Rotation
我找到了我自己的问题的解决方案。 我所要做的就是:
[Activity(Label = "Menu", Icon = "@drawable/Icon", ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)]
配置更改 = Android.Content.PM.ConfigChanges.Orientation
这已经解决了问题,但我认为可能有更好的解决方案,因此欢迎任何其他解决方案。