1

When user opens any application by clicking on app icon, the app starts with mainactivity.java. and its xml layout is shown to user. I am making a splash screen with simple background color and text. But what my problem is, when it starts it shows a default layout color for a very little fraction of time and then it draws my given color. I do not want default color to be there even for that small fraction of time.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.rushi.demon.MainActivity"
android:background="@color/SplashScreen" >

<RelativeLayout
    android:id="@+id/SplashScreen"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/SplashScreen">


    <TextView
        android:id="@+id/SplashText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:text="@string/splash_name"
        android:textColor="@color/SplashText"
        android:textSize="40sp"
        android:textStyle="bold"/>
</RelativeLayout>


</android.support.constraint.ConstraintLayout>

The SplashScreen color is shown after a lag and starting default color is shown for little time, which i do not want. I want to open this activity with my set color only from starting.

  • 1
    Check this question, it will solve your problem: - https://stackoverflow.com/questions/48536680/what-is-the-reason-for-white-screen-on-launch-of-app-how-to-avoid-it-completel/48536958#48536958 – Aditya Feb 19 '18 at 09:40
  • did you see the default color on tabbar? – 007 Feb 19 '18 at 09:43
  • possible duplicate of: https://stackoverflow.com/questions/20546703/how-to-fix-white-screen-on-app-start-up – Kakumanu siva krishna Feb 19 '18 at 09:46

2 Answers2

1

Add this to your AppTheme (theme of MainActivity) ..

<item name="android:windowDisablePreview">true</item>

Edit Go to app -> res -> values -> styles.xml open styles.xml there you do this to the theme you have..

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowDisablePreview">true</item> //add this line
    </style>
Santanu Sur
  • 10,997
  • 7
  • 33
  • 52
0

The best way to achieve this is well described here, By this way Splash Activity will start instantly

Refer this: https://medium.com/@ssaurel/create-a-splash-screen-on-android-the-right-way-93d6fb444857

Milind Mevada
  • 3,145
  • 1
  • 14
  • 22