2016-12-16 20 views
0

我是從這個問題,試圖建議#2: Android display Splash-Screen while loading安卓顯示啓動畫面同時加載,但得到的黑色屏幕而不是

這是使用一個主題,然後一個背景繪製從Splash.java加載MainActivity它使用所述主題在MainActivity處理和加載時顯示圖像。

我得到一個黑屏幾秒鐘,然後主屏幕出現在第一次加載。

我錯過了什麼嗎?或者這個工作正常嗎?如果它工作正常,如果可能,我如何獲取圖像而不是黑屏?

@繪製/ 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

哪裏是你的閃屏XML。 – Champandorid

+0

http://stackoverflow.com/a/15832037/6478047看到這個參考 – Redman

+1

你正在使用'Splash extends Activity',你必須使用'Splash extends AppCompatActivity'。 – Ironman

回答

0

我不得不在風格主題添加父得到它的工作。感謝您在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

我認爲你的Flash屏幕沒有加載,因爲你沒有設置任何閃屏時間。
嘗試打擊代碼:

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

無法解析構造函數的'意圖' 我真的只想讓它在啓動時顯示(做一些事情,而沒有可見的屏幕)我的印象是,它會顯示,而不是我得到的黑屏。 – naps1saps

0

//這是爲我工作。 //這是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(); 
    } 

} 

//這是我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> 
相關問題