سلام
من با زامارین فرمز یه splash screen ساختم. کدهام هم کاملا درسته(چندین فیلم و فایل آموزشی دیدم همینطوری نوشته بودن)
ولی وقتی اجرا میکنم صفحه splash سریع باز و بسته میشه و فرمی که باید بعدش بیاد، نمیاد.
کد MainActivity
namespace SplashScreen.Droid { [Activity(Label = "SplashScreen", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity { protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); global::Xamarin.Forms.Forms.Init(this, bundle); LoadApplication(new App()); } } }
کد SplashActivity
namespace SplashScreen.Droid { [Activity(Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true)] public class SplashActivity : Activity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // System.Threading.Thread.Sleep(10000); Thread.Sleep(5000); StartActivity(typeof(MainActivity)); Finish(); // OverridePendingTransition( 0 , 0); // Create your application here } protected override void OnResume() { base.OnResume(); StartActivity(typeof(MainActivity)); } } }
کد styles
<?xml version="1.0" encoding="utf-8" ?> <resources> <style name="Theme.Splash" parent="android:Theme"> <item name="android:windowBackground">@drawable/oxinsteel</item> <item name="android:windowNoTitle">true</item> <item name="android:windowFullscreen">true</item> </style> <style name="MainTheme" parent="MainTheme.Base"> </style> <!-- Base theme applied no matter what API --> <style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> <!--If you are using revision 22.1 please use just windowNoTitle. Without android:--> <item name="windowNoTitle">true</item> <!--We will be using the toolbar so no need to show ActionBar--> <item name="windowActionBar">false</item> <!-- Set theme colors from http://www.google.com/design/spec/style/color.html#color-color-palette --> <!-- colorPrimary is used for the default action bar background --> <item name="colorPrimary">#2196F3</item> <!-- colorPrimaryDark is used for the status bar --> <item name="colorPrimaryDark">#1976D2</item> <!-- colorAccent is used as the default value for colorControlActivated which is used to tint widgets --> <item name="colorAccent">#FF4081</item> <!-- You can also set colorControlNormal, colorControlActivated colorControlHighlight and colorSwitchThumbNormal. --> <item name="windowActionModeOverlay">true</item> <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item> </style> <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog"> <item name="colorAccent">#FF4081</item> </style> </resources>
کد App.xaml.cs
namespace SplashScreen { public partial class App : Application { public App () { InitializeComponent(); MainPage = new SplashScreen.MainPage(); } protected override void OnStart () { // Handle when your app starts } protected override void OnSleep () { // Handle when your app sleeps } protected override void OnResume () { // Handle when your app resumes } } }
این آموزش هایی که خوندم در مورد تغییر در android manifest چیزی نگفته بودن. لازمه تغییراتی توی manifest بدم یا نه؟؟؟؟
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)