I'm developing an app with splash screen. At the beginning the splash screen only had a background image. I added a style in Resources/values/styles.xml
file:
<style name="Theme.Splash" parent="android:Theme"> <item name="android:windowBackground">@drawable/splash_screen_image</item> <item name="android:windowNoTitle">true</item> <item name="android:windowFullscreen">true</item> <item name="colorPrimaryDark">#313131</item> </style>
And I used it as SplashActivity
's theme, (and I set the activity as main launcher):
[Activity(Label = "MY APP", Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true, Icon = "@mipmap/ic_launcher", RoundIcon = "@mipmap/ic_round_launcher", ScreenOrientation = ScreenOrientation.Portrait)] public class SplashActivity : Activity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.StartActivity(typeof(MainActivity)); } }
It worked fine, it showed the image at startup. Now I want to add the app version to the splash screen. I created SplashScreen.axml
layout file with an image and a label with "hardcoded" version number on the bottom left corner:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="#000000" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:src="@drawable/splash_screen_image" android:layout_height="match_parent" android:layout_width="match_parent" android:scaleType="centerCrop" android:padding="0dp" android:adjustViewBounds="true" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="V0.6" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="#FFFFFF" android:id="@+id/version_text_view" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_marginLeft="5dp" android:layout_marginBottom="5dp"/> </RelativeLayout>
And added this content view in SplashActivity
:
[Activity(Label = "MY APP", Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true, Icon = "@mipmap/ic_launcher", RoundIcon = "@mipmap/ic_round_launcher", ScreenOrientation = ScreenOrientation.Portrait)] public class SplashActivity : Activity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.SplashScreen); this.StartActivity(typeof(MainActivity)); } }
In this case nothing happens, the Theme.Splash
is displayed. Then I changed OnCreate
method to start MainActivity
using a timer:
[Activity(Label = "Cocina Tiflotécnica", Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true, Icon = "@mipmap/ic_launcher", RoundIcon = "@mipmap/ic_round_launcher", ScreenOrientation = ScreenOrientation.Portrait)] public class SplashActivity : Activity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.SplashScreen); Timer timer = new Timer(); timer.Interval = 10; // 10 millis. timer.AutoReset = false; // Do not reset the timer after it's elapsed timer.Elapsed += (object sender, ElapsedEventArgs e) => { this.StartActivity(typeof(MainActivity)); }; timer.Start(); } }
In this case Theme.Splash
is displayed first (a few seconds) and then Resource.Layout.SplashScreen
layout with version number (a few seconds too). The background image is fit in different way in the theme and the layout, so the background changing is very noticeable.
Is there an elegant way to show a background with a text in the splash screen?