Forum Xamarin.Android

Splash Screen With text

eman86eman86 USMember ✭✭

I'm following the following article on Splash Screens

https://developer.xamarin.com/guides/android/user_interface/creating_a_splash_screen/

and I got a working solution but I'd like to show the version of the app when the Splash screen is shown and a bonus would be a loading circle as well.

but I am at a loss on how to do this.

Best Answer

Answers

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭✭
    edited May 2016

    Hello, i'm not a pro i'm a beginner since several day but i've search on internet and the main solution for your problem i've found is to make a gif image with text

    i've try to make a project (splash screen) add a layout for the splash screen with a text view with some text but my text view is never display with the text
    i don t know why....
    Now, if i comment these lines
    System.Threading.Thread.Sleep(3000); StartActivity(typeof(MainActivity));
    of course the text view will be show but my app never ...

    Have a good luck for your task

  • eman86eman86 USMember ✭✭

    Awesome ,thanks a lot RobertBruce

  • batmacibatmaci DEMember ✭✭✭✭✭
    edited October 2016

    @RobertBruce said:
    Hi eman86,

    I put this together for you--a splash screen with a spinning circle and text showing the app version.

    Hope it helps!

    SplashScreen.axml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="100dp">
        <ProgressBar
            android:id="@+id/pbSpinningCircle"
            android:indeterminateOnly="true"
            android:keepScreenOn="true"
            android:layout_width="20px"
            android:layout_height="20px"
            android:background="@android:color/transparent" />
        <TextView
            android:id="@+id/txtLoading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/pbSpinningCircle"
            android:layout_alignTop="@+id/pbSpinningCircle"
            android:textColor="#fff"
            android:text="Loading..."
            android:layout_marginLeft="5dp"
            android:textSize="14sp"
            android:background="@android:color/transparent" />
        </LinearLayout>
        <TextView
            android:id="@+id/txtAppVersion"
            android:text="[APP_VERSION]"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginLeft="30dp"
            android:layout_marginBottom="30dp"
            android:textColor="#fff"
            android:textSize="14sp"
            android:background="@android:color/transparent" />
    </RelativeLayout>
    

    SplashScreen.cs

    using Android.App;
    using Android.Content.PM;
    using Android.OS;
    using Android.Widget;
    
    namespace XamdroidMaster.Activities {
    
        [Activity(Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true, Immersive = true, ScreenOrientation = ScreenOrientation.Portrait)]    
        public class SplashScreenActivity : Activity {
            protected override void OnCreate(Bundle savedInstanceState) {
                base.OnCreate(savedInstanceState);
                SetContentView(Resource.Layout.SplashScreen);            
                FindViewById<TextView>(Resource.Id.txtAppVersion).Text = $"Version {PackageManager.GetPackageInfo(PackageName, 0).VersionName}";            
            }
        }
    }
    

    Cheers!

    @RobertBruce It works fine but there is a black screen in between when i am debugging on device. and I am only seeing the progressbar if put System.Threading.Thread.Sleep(5000); before StartActivity(typeof(MainActivity)); btw where is this line in your code?

  • AMAXAMAX USMember ✭✭

    @RobertBruce said:
    Hi eman86,

    I put this together for you--a splash screen with a spinning circle and text showing the app version.

    Hope it helps!

    SplashScreen.axml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="100dp">
        <ProgressBar
            android:id="@+id/pbSpinningCircle"
            android:indeterminateOnly="true"
            android:keepScreenOn="true"
            android:layout_width="20px"
            android:layout_height="20px"
            android:background="@android:color/transparent" />
        <TextView
            android:id="@+id/txtLoading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/pbSpinningCircle"
            android:layout_alignTop="@+id/pbSpinningCircle"
            android:textColor="#fff"
            android:text="Loading..."
            android:layout_marginLeft="5dp"
            android:textSize="14sp"
            android:background="@android:color/transparent" />
        </LinearLayout>
        <TextView
            android:id="@+id/txtAppVersion"
            android:text="[APP_VERSION]"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginLeft="30dp"
            android:layout_marginBottom="30dp"
            android:textColor="#fff"
            android:textSize="14sp"
            android:background="@android:color/transparent" />
    </RelativeLayout>
    

    SplashScreen.cs

    using Android.App;
    using Android.Content.PM;
    using Android.OS;
    using Android.Widget;
    
    namespace XamdroidMaster.Activities {
    
        [Activity(Theme = "@android:style/Theme.NoTitleBar", MainLauncher = true, Immersive = true, ScreenOrientation = ScreenOrientation.Portrait)]    
        public class SplashScreenActivity : Activity {
            protected override void OnCreate(Bundle savedInstanceState) {
                base.OnCreate(savedInstanceState);
                SetContentView(Resource.Layout.SplashScreen);            
                FindViewById<TextView>(Resource.Id.txtAppVersion).Text = $"Version {PackageManager.GetPackageInfo(PackageName, 0).VersionName}";            
            }
        }
    }
    

    Cheers!

    Can't Add ".axml" file its changes automatically into .xml file,

    what folder should I add the SplashScreen.axml file?

  • JamesTheButlerJamesTheButler Member

    @AMAX said:
    Can't Add ".axml" file its changes automatically into .xml file,

    what folder should I add the SplashScreen.axml file?

    Add a new XML file and manually rename it to .axml.
    Add it to Resources\layout folder

Sign In or Register to comment.