16387

Xamarin : Splash screen using a Layout

Question:

I am trying to create splash screen for my android application, as shown in this link <a href="http://developer.xamarin.com/guides/android/user_interface/creating_a_splash_screen/" rel="nofollow">http://developer.xamarin.com/guides/android/user_interface/creating_a_splash_screen/</a>

Unfortunately this link just shows how to make a splash screen using a drawable. But what I need to do is to create a splash screen using a Layout so that I can easily customize how it looks and make it compatible with different screen sizes.

Thanks

Answer1:

What you can do is to create a Activity that represents your splash screen. Ex: SplashActivity. Then when your SplashActivity is created you start a timer (Ex: System.Timers.Timer) with 3 seconds duration. When those 3 seconds have passed you simply start the main activity for your app.

To prevent the user from navigating back to the splash activity, you simply add the NoHistory = true property to the ActivityAttribute (just above the activity class decleration).

See example:

[Activity(MainLauncher = true, NoHistory = true, Label = "My splash app", Icon = "@drawable/icon")] public class SplashActivity : Activity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Splash); Timer timer = new Timer(); timer.Interval = 3000; // 3 sec. timer.AutoReset = false; // Do not reset the timer after it's elapsed timer.Elapsed += (object sender, ElapsedEventArgs e) => { StartActivity(typeof(MainActivity)); }; timer.Start(); } }; [Activity (Label = "Main activity")] public class MainActivity : Activity { protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); } }

Recommend

  • Thread stopping issue android
  • How to show toast at Splash Screen
  • Can not Resolved FirebaseOptions.Builder().setCredentials()
  • Checking internet connection in android using getActiveNetworkInfo
  • Is changing parent process necessary when daemonize a process?
  • how to perform a modal segue for long press
  • A floating button fixed at the bottom of UITableview with scrollViewDidScroll not working properly
  • How to make splash screen not to load if app is already in memory
  • iOS timer outside application
  • URL detection adobe air desktop widget
  • How to handle exception using Timer (Thread) class
  • Is there a way to stop/re-start ejb 3.1 automatic timer during runtime?
  • How do js animations work?
  • SharePoint timer job add list items, but does not trigger the associated workflow
  • Equivalent for np.add.at in tensorflow
  • EJB @Schedule issue
  • powershell: script to start a program with parameters?
  • NSTimer and updating UI
  • GDB skips over my code!
  • Lua string.gsub() by '%s' or '\\n' pattern
  • EditText is covered by Keyboard
  • Receive mouse move even cursor is outside control
  • Faster Way To Simultaneously Iterate Over Rolling Window Of Two Or More Numpy Arrays?
  • URLConnection doesn't work since API 10 and higher?
  • Create Instant using a negative year
  • print() is showing quotation marks in results
  • Unity3D & Android: Difference between “UnityMain” and “main” threads?
  • Q promise. Difference between .when and .then
  • Illegal mix of collations for operation for date/time comparison
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • retrieve vertices with no linked edge in arangodb
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Proper folder structure for lots of source files
  • python regex in pyparsing
  • Android Google Maps API OnLocationChanged only called once
  • How does Linux kernel interrupt the application?
  • unknown Exception android
  • How can I use threading to 'tick' a timer to be accessed by other threads?