Hi there!
I'm trying to create a splash screen with image and text.
There are several samples on the net. I'm trying to reproduce some of them with no success. I only got blank screen.
My device is running SANSUNG Android 6.0.1
My code is:
THEME (file ... Resources\values\styles.xml)
LAYOUT (file ... Resources\layout\splash_screen_text.xml)
ACTIVITY (file SplashScreenTextActivity.cs)
Any idea?
I tested a basic demo about SplashScreen useing LinearLayout and it works on my side.
[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)] public class SplashActivity : AppCompatActivity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.layout1); } protected override void OnResume() { base.OnResume(); Task startupWork = new Task(() => { SimulateStartup(); }); startupWork.Start(); } async void SimulateStartup() { await Task.Delay(2000); StartActivity(new Intent(Application.Context, typeof(MainActivity))); } }
Here is the sample file, you can refer to it.
Answers
Because you didn't specify the windowBackground in style.xml. You need to create a drawable for splash screen and implement a theme.
style.xml
drawable\splash_screen.xml
Check the tutorial:
https://docs.microsoft.com/en-us/xamarin/android/user-interface/splash-screen
Jarvan, thanks to reply.
Note, I'm not using layer-list as layout for splash screen. I using LinearLayout because I need to put image and text in my splash screen.
Any suggestion?
I tested a basic demo about SplashScreen useing LinearLayout and it works on my side.
Here is the sample file, you can refer to it.
After add the task "SimulateStartup" the problem was solved.
I was calling StartActivity(new Intent(Application.Context, typeof(MainActivity))); not as as Task.
Thank you Jarvan!
@Jarvan Is there a way I can skip the layer-list .xml and show directly the .axml file?