Several simple implementations of the splash of xamarin.android

Source: Internet
Author: User

For today's app software, there will basically be a splash page, similar to what we often say welcome page, launch interface and so on.

Normally this page will have some relevant information, such as some ideas, logos, version information, etc.

Let's take a look at how easy it is to implement Xamarin.android.

First, create a blank Android project two, add a layout,splash.axml
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 android:orientation= "vertical"4 Android:layout_width= "Match_parent"5 Android:layout_height= "Match_parent">6     <TextView7         Android:layout_width= "Match_parent"8 Android:layout_height= "Wrap_content"9 Android:text= "Splash page"Ten android:textsize= "50SP" One Android:layout_margintop= "150DP" A android:gravity= "Center" /> -     <LinearLayout -         android:orientation= "vertical" the Android:layout_width= "Match_parent" - Android:layout_height= "Match_parent" - android:gravity= "Bottom"> -         <TextView +             Android:layout_width= "Match_parent" - Android:layout_height= "Wrap_content" + android:textsize= "20SP" A Android:id= "@+id/tv_version" at android:gravity= "Center" /> -     </LinearLayout> - </LinearLayout>  

The content is relatively simple, several text and app version information.

Third, add an activity, splashactivity
1 usingAndroid.app;2 usingandroid.content;3 usingAndroid.Content.PM;4 usingAndroid.os;5 usingAndroid.widget;6 usingSystem.Threading;7 usingSystem.Threading.Tasks;8 9 namespaceCatcher.AndroidDemo.SplashDemoTen { One[Activity (Label ="splashactivity", Mainlauncher =true, nohistory =true, Theme ="@android: Style/theme.black.notitlebar.fullscreen")] A      Public classsplashactivity:activity -     { -         protected Override voidOnCreate (Bundle savedinstancestate) the         { -             Base. OnCreate (savedinstancestate); -              - Setcontentview (Resource.Layout.splash); +             //version ' s infomation -             varTvversion = findviewbyid<textview>(Resource.Id.tv_version);  +Tvversion.text ="Version"+ Packagemanager.getpackageinfo ( This. Packagename,packageinfoflags.matchall). Versionname; A            //Method 1: at             //using Java to write Android should be more familiar -             NewHandler (). Postdelayed (() = -             { -Intent Intent =NewIntent ( This,typeof(mainactivity)); - startactivity (intent); -                  This. Finish (); in}, the); -             //Method 2: to             //It just sleeps for 5 seconds and then flashes the page and jumps to the main page. +             //Thread.Sleep (the); -             //This . StartActivity (typeof (Mainactivity)); the             //This . Finish (); *             //Method 3: $             //This writing improves the appearance of the second form of the problemPanax Notoginseng             //thread thread = new Thread (() = -             //{ the             //Thread.Sleep (5000);  +             //Intent Intent = new Intent (this, typeof (Mainactivity)); A             //startactivity (intent); the             //This . Finish (); +             //});  -             //thread. Start (); $             //Method 4: $             //use task to implement -             //Task task = new Task (() = -             //{ the             //Task.delay (5000);  -             //});Wuyi             //task. ContinueWith (t = the             //{ -             //startactivity (New Intent (This, typeof (Mainactivity))); Wu             //This . Finish (); -             //},taskscheduler.fromcurrentsynchronizationcontext ()); About             //task.  Start ();  $         } -     } -}

In Splashactivity, several simple implementations have been written. Let's talk about it from beginning to end.

Mainlauncher = True indicates that our activity is the first to start, and remember to change this property of the mainactivity generated by the new project to False or remove

Nohistory =true See the name of the idea ~ ~

Theme = "@android: Style/theme.black.notitlebar.fullscreen"

This is the theme, the default has a lot of many, for convenience there is no way to write one, but in the default theme to choose a no title bar, full-screen display

You can open the design page and see how many

Packagemanager.getpackageinfo ( this

This is the version of the app to remove the information.

The first method is implemented by instantiating an handler object and invoking the Postdelayed method of the object. This approach is relatively close to Java development of the kind of writing.

There are two overloads of the Postdelayed method

1          Public BOOL Long delaymillis); 2         [Register ("postdelayed" "(ljava/lang/runnable; J) Z"" ")]3public         boolLong Delaymillis);  

The first one is the direct use of the delegate to achieve, this is the method used in this article.

The second use is runnable, the specific wording can refer to the following:

1           New Handler (). Postdelayed (new Java.Lang.Runnable () =2            {3                 new Intent (  This typeof (mainactivity)); 4                 startactivity (intent); 5                  This . Finish (); 6             );  

Look at runnable.

1     [Register ("mono/java/lang/runnable")] 2      Public Sealed class Runnable:object, Irunnable, Ijavaobject, IDisposable 3     {4public           Runnable (Action handler); 5          Public void Run (); 6     }  

In the end we have to use the word or we have to pass a commissioned past, the effect is consistent with the method in the text.

The second method is straightforward, dormant for a period of time out, but this method seems to use is not cool, because regardless of sleep time

Set how long, is at the end of sleep time, suddenly flashed a splash page and then to the main page. If I was starting

There are animations on the page, and that's not a pit.

The third method, which can be said to be improved on the basis of the second method, can achieve the same effect as other methods.

The fourth method, using task to implement. This is also an example of a method used in the official website. But the effect of this method

is not ideal, the Splashd page appears in less than 5 seconds (probably stopped 2, 3 seconds) jump to the main page.

There are several ways to start a single activity in these methods, which can be selected with personal preference.

Finally, put a picture.

Example code:

Https://github.com/hwqdt/Demos/tree/master/src/Catcher.AndroidDemo/Catcher.AndroidDemo.SplashDemo

Several simple implementations of the splash of xamarin.android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.