2016-12-16 3 views
0

J'essaie suggestion # 2 de cette question: Android display Splash-Screen while loadingécran Android Splash écran pendant le chargement, mais obtenir un écran noir à la place

est d'utiliser un thème avec un drawable de fond puis chargement MainActivity de Splash.java qui utilise ledit thème pour afficher une image pendant que MainActivity traite et charge.

Je reçois un écran noir pendant plusieurs secondes puis l'écran principal apparaît au premier chargement.

Ai-je raté quelque chose? Ou est-ce que cela fonctionne correctement? Si cela fonctionne correctement, comment puis-je obtenir une image à afficher à la place de l'écran noir si possible?

@ étirables/background_splash

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

    <!-- Fill the background with a solid color --> 
    <item 
     android:drawable="@color/colorPrimary"/> 
    <item> 

     <!-- Place your bitmap in the center --> 
     <bitmap 
      android:gravity="center" 
      android:src="@mipmap/ic_launcher"/> 
    </item> 

</layer-list> 

@styles

<resources> 

<!-- Base application theme. --> 
<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> 
</style> 

<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
</style> 

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> 

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> 

<!-- Splash Screen theme --> 
<style name="SplashTheme"> 
    <item name="android:background">@drawable/background_splash</item> 
    <item name="android:windowAnimationStyle">@null</item> 
</style> 

</resources> 

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.epicdecals.openslider"> 

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> 
<uses-permission android:name="android.permission.BLUETOOTH"/> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/open_slider_icon" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 

    <activity android:name=".Splash" 
     android:theme="@style/SplashTheme"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme.NoActionBar"> 
    </activity> 

</application> 

</manifest> 

Splash.java

public class Splash extends AppCompatActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    Intent intent = new Intent(this, MainActivity.class); 
    startActivity(intent); 
    finish(); 
} 
} 
+0

Où est votre xml pour écran de démarrage. – Champandorid

+0

http://stackoverflow.com/a/15832037/6478047 voir ceci pour la référence – Redman

+1

vous utilisez 'Splash extends Activity', vous devez utiliser cette' Splash extends AppCompatActivity'. – Ironman

Répondre

0

je devais ajouter un parent dans le thème de style pour le faire fonctionner. Merci pour le lien dans les commentaires Redman ^^^^.

EX:

<style name="SplashTheme" 
    parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="android:background">@drawable/background_splash</item> 
    <item name="android:windowAnimationStyle">@null</item> 
</style> 
0

Je pense que votre écran Flash n'est pas chargé parce que vous n'avez pas défini l'heure de l'écran de démarrage.
Essayez code coup:

public class Splash extends Activity { 

private CountDownTimer timer = null; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_splash); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    timer = new CountDownTimer(2000, 1000) { 

     @Override 
     public void onTick(long millisUntilFinished) { 

     } 

     @Override 
     public void onFinish() { 
       Intent intent = new Intent(this, MainActivity.class); 
       startActivity(intent); 
       finish(); 
     } 
    }; 
} 

@Override 
protected void onResume() { 
    super.onResume(); 
    timer.start(); 
} 

@Override 
protected void onPause() { 
    super.onPause(); 
    timer.cancel(); 
} 

@Override 
protected void onDestroy() { 
    super.onDestroy(); 
    timer = null; 
} 
+0

Impossible de résoudre le constructeur 'intention' Je ne veux vraiment que le montrer au démarrage (faire quelque chose alors qu'aucun écran n'est visible) J'avais l'impression qu'il montrerait au lieu de l'écran noir que je reçois. – naps1saps

0

// Cela fonctionne pour moi. // C'est Splash.java

public class Splash extends ActionBarActivity 
{ 



    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_splash); 

      Thread th = new Thread() { 
      public void run() { 
       try { 
        sleep(1000); 
       } catch (InterruptedException e) { 
        e.printStackTrace(); 
       } finally { 
        // write your activity which you want to open 

      Intent intent = new Intent(Splash.this, MainActivity.class); 
         startActivity(intent); 
         finish(); 

       } 
      } 
     }; 
     th.start(); 
    } 

} 

// et ceci est mon Splash.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:background="@drawable/bk_client" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:gravity="center" 
     android:layout_centerInParent="true"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/logo" 
     android:layout_centerInParent="true"/> 

     </LinearLayout> 

</RelativeLayout>