Man*_*dan 5 c# xamarin.android xamarin.forms
我使用xamarin表单创建新的移动应用程序.我必须创建两个页面登录屏幕和主屏幕.我从这里得到样品
但是,当我创建相同的我不能去第二页.它始终只保留登录页面.
在我的Android MainActivity代码中
public class MainActivity : AndroidActivity, LoginManager
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Xamarin.Forms.Forms.Init(this, bundle);
SetPage(App.GetLoginPage(this));
// SetPage(App.GetLoginPage(this));
}
#region ILoginManager implementation
public void ShowMainPage()
{
SetPage(App.GetHomePage(this));
}
public void Logout()
{
SetPage(App.GetLoginPage(this));
}
#endregion
}
Run Code Online (Sandbox Code Playgroud)
第二次调用setPage方法但页面内容未被替换.请帮助任何人
这是针对 Android 的第二组页面问题的解决方法。创建第二个界面,而不是在现有活动上使用设置页面启动一个新活动,其中新活动的 OnCreate 调用设置页面并完成当前活动。
应用程序.cs
public static ILoginManager LoginManager;
public static IAppNavigation SplashManger;
public static Page GetLoginPage(ILoginManager lmanager)
{
LoginManager = lmanager;
return new Page_Login();
}
public static Page GetShowSplashPage(IAppNavigation iSplashNavigation)
{
SplashManger = iSplashNavigation;
return new Page_Splash();
}
Run Code Online (Sandbox Code Playgroud)
Android 主活动
[Activity(Label = "", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : AndroidActivity, IAppNavigation
{
protected override void OnCreate(Bundle bundle)
{
//Window.RequestFeature(WindowFeatures.NoTitle);
base.OnCreate(bundle);
Xamarin.Forms.Forms.Init(this, bundle);
SetPage(App.GetShowSplashPage(this));
}
public void GetLoginPage()
{
StartActivity(new Intent(this, typeof(LoginActivity)));
Finish();
}
Run Code Online (Sandbox Code Playgroud)
Android 登录活动
[Activity(Label = "", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class LoginActivity : AndroidActivity, ILoginManager
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Xamarin.Forms.Forms.Init(this, bundle);
SetPage(App.GetLoginPage(this));
}
public void GetMainMenu()
{
StartActivity(new Intent(this, typeof(MainMenuActivity)));
Finish();
}
Run Code Online (Sandbox Code Playgroud)
在 iOS 中,您不需要做任何特殊的事情,只需实现您将在 App delegate 中使用的所有必要接口即可。
iOS 应用程序代理
[Register("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate, ILoginManager, IAppNavigation
{
// class-level declarations
UIWindow window;
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Forms.Init();
window = new UIWindow(UIScreen.MainScreen.Bounds);
window.RootViewController = App.GetShowSplashPage(this).CreateViewController();
window.MakeKeyAndVisible();
return true;
}
public void GetMainMenu()
{
window.RootViewController = App.GetMainMenu().CreateViewController();
window.MakeKeyAndVisible();
}
public void GetLoginPage()
{
window.RootViewController = App.GetLoginPage(this).CreateViewController();
window.MakeKeyAndVisible();
}
Run Code Online (Sandbox Code Playgroud)