2016-05-10 96 views
1

在加載啓動畫面時最小化應用程序時會顯示帶有應用程序標題的黑色屏幕,同時第一個屏幕會在一段時間後顯示。這是我的飛濺活動和主要活動課程。Xamarin形式啓動畫面問題

[Activity(Theme = "@style/Theme.Splash", Icon = "@drawable/icon", MainLauncher = true, NoHistory = true, 
    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, 
    ScreenOrientation = ScreenOrientation.Behind)] 
public class SplashActivity : Activity 
{ 
    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     var dpWidth = Resources.DisplayMetrics.WidthPixels/Resources.DisplayMetrics.Density; 


     RequestedOrientation = dpWidth > 700 ? ScreenOrientation.Unspecified : ScreenOrientation.Portrait; 

     ThreadPool.QueueUserWorkItem(o => LoadActivity()); 
    } 

    private void LoadActivity() 
    { 

     RunOnUiThread(() => StartActivity(typeof(MainActivity))); 
    } 


    public override void OnBackPressed() 
    { 
     Environment.Exit(0); 
    } 
} 



[Activity(Label = "HACCP", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] 
public class MainActivity : FormsApplicationActivity 
{ 


    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 
     ActionBar.SetIcon(Android.Resource.Color.Transparent); 

     Forms.Init(this, bundle); 

     // some function // 

     LoadApplication(new App()); 
    } 

} 
+0

問題是固定的。 –

回答

0

不能確定的活動屬性ScreenOrientation = ScreenOrientation.Behind)造成的任何問題,我們不使用,在我們的應用程序。

這裏是我們使用「標準」撲通活動,讓Xamarin.Android採取定時等的護理:

public class SplashActivity : Activity 
{ 
    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     // Start main. 
     StartActivity(typeof(MainActivity)); 
    } 
} 

您可以嘗試以類似的方式簡化您的應用程序。

1

您標記Xamarin.Forms所以應該那樣簡單.. NoHistory標誌設置爲false時

class App : Application 
{ 
    public App() 
    { 
     MainPage = new MySplashPage(); 
    } 
} 

class MySplashPage : ContentPage 
{ 
    public MySplashPage() 
    { 
     Task.Delay(3000); //show my pretty splash for 3 seconds 
     Application.Current.MainPage = new MyOtherSpiffyPage(); 
    } 
}