Search code examples
androidlayoutbackground-color

Change the default color of main activity when it starts, The starting and opening default color


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.


Solution

  • 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>