Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

blank screen comes before splash

The main problem is the splash screen appears after 2-3 seconds. Before splash screen a blank layout appears which I don't want. Otherwise it runs fine. Just want to remove the blank layout which appears before the splash page.

MainActivity:

public class MainActivity extends Activity {      private static String TAG = MainActivity.class.getName();     private static long SLEEP_TIME = 5; // Sleep for some time      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);          this.requestWindowFeature(Window.FEATURE_NO_TITLE); // Removes title bar         this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  // Removes notification bar          setContentView(R.layout.activity_main);          // Start timer and launch main activity         IntentLauncher launcher = new IntentLauncher();         launcher.start();     }      private class IntentLauncher extends Thread {          @Override         /**          * Sleep for some time and than start new activity.          */         public void run() {             try {                 // Sleeping                 Thread.sleep(SLEEP_TIME*1000);             } catch (Exception e) {                 Log.e(TAG, e.getMessage());             }              // Start main activity             Intent intent = new Intent(MainActivity.this, Login.class);             MainActivity.this.startActivity(intent);             MainActivity.this.finish();         }     }  } 

main layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingBottom="@dimen/activity_vertical_margin"     android:paddingLeft="@dimen/activity_horizontal_margin"     android:paddingRight="@dimen/activity_horizontal_margin"     android:paddingTop="@dimen/activity_vertical_margin"     android:background="@drawable/splash"     tools:context=".MainActivity" >  </RelativeLayout> 
like image 511
Somnath Pal Avatar asked May 20 '15 07:05

Somnath Pal


People also ask

How do I get rid of white screen before splash screen flutter?

On the right in the properties, there is the background attribute. Clicking on this and choosing custom will allow you to define the RGB value you'd like the colour of the white screen to now appear as. Running your app on Android and iOS will now no longer show the annoying white screen.

Is splash screen the same as loading screen?

"Splash screens may be an innocuous part of the user experience." "A splash screen is a screen which appears when you open an app on your mobile device." "Sometimes it's referred to as a launch screen or startup screen and shows up when your app is loading after you've just opened it."

How do I get rid of the default splash screen?

Basically what you've to do is override your splash screen theme in res\values-v31\themes. xml & set a transparent icon. This will get you rid of the default app icon that appears during splash when the app is launch.


2 Answers

Generally speaking, splash screens are not recommended for an app but if you really must.

Android will load a blank layout before it loads an activity layout based on the theme you have set for it. The solution is to set the theme of the splash activity to a transparent one.

Create a transparent theme in res/values/styles.xml

<?xml version="1.0" encoding="utf-8"?> <resources>    <style name="Theme.Transparent" parent="android:Theme">       <item name="android:windowIsTranslucent">true</item>       <item name="android:windowBackground">@android:color/transparent</item>       <item name="android:windowContentOverlay">@null</item>       <item name="android:windowNoTitle">true</item>       <item name="android:windowIsFloating">true</item>      <item name="android:backgroundDimEnabled">false</item>   </style> </resources> 

Then set the theme in your manifest

<activity android:name=".SplashActivity" android:theme="@style/Theme.Transparent"> ... </activity> 
like image 98
Eoin Avatar answered Oct 04 '22 07:10

Eoin


It's better to use a Themed background for your starting activity but if you don't want the blank screen appears before launching main activity you can define your activity like this:

Add android:windowDisablePreview to your AppTheme in res/values/styles.xml:

<?xml version="1.0" encoding="utf-8"?> <resources>    <style name="AppTheme" parent="android:Theme">         <item name="android:windowDisablePreview">true</item>   </style> </resources> 

Then set your activity theme in your manifest:

<activity android:name=".MainActivity" android:theme="@style/AppTheme"> ... </activity> 

P.S: Setting android:windowDisablePreview has no effect on your activity background, so you have nothing to worry.

like image 25
Keivan Esbati Avatar answered Oct 04 '22 07:10

Keivan Esbati