2015-08-24 76 views
-6

我已經嘗試添加閃屏到我的應用程序,而他們這樣做的主要活動前表示,該屏幕還總是顯示不管是什麼:如何擺脫這個默認的啓動畫面?

pic

這裏是MainActivity代碼:

public class MainActivity extends Activity implements WelcomeFragment.StartQuestions, QuestionFragment.QuestionsAnswered { 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    Parse.enableLocalDatastore(this); 
    Parse.initialize(this, "***************************", "*****************************"); 
    super.onCreate(savedInstanceState); 
    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 

    setContentView(R.layout.activity_main); 
    loadingIcon = (ProgressBar) findViewById(R.id.loadingIcon); 
    loadingIcon.setVisibility(View.GONE); 
    checkInternetConnection(); 

    showWelcomeScreen(); 
} 
} 

showWelcomeScreen():

public void showWelcomeScreen(){ 
    Fragment fragment = getFragmentManager().findFragmentById(R.id.fragmentContainer); 

    if (fragment == null){ 
     fragment = new WelcomeFragment(); 
     getFragmentManager().beginTransaction() 
       .add(R.id.fragmentContainer, fragment) 
       .commit(); 
    } else { 
     fragment = new WelcomeFragment(); 
     getFragmentManager().beginTransaction() 
       .replace(R.id.fragmentContainer, fragment) 
       .commit(); 
    } 
} 

activity_main.xml中:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/fragmentContainer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

<RelativeLayout 
    android:id="@+id/loadingPanel" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    > 

    <ProgressBar 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:indeterminate="true" android:id="@+id/loadingIcon"/> 
</RelativeLayout> 

在MainActivity,我已經指定去除頂部條: this.requestWindowFeature(Window.FEATURE_NO_TITLE);

軟件本身不具備吧。在啓動應用程序時,我將任何作爲默認設置放置在清單中的活動(充當啓動屏幕)仍然通過上面顯示的屏幕進行。

+0

發佈您的主要活動代碼。 –

+0

您需要爲您的問題添加相關代碼才能幫助您 – PPartisan

+0

抱歉。我認爲這是一個每個人都得到的默認屏幕,不管他們的活動代碼 – dbalagula23

回答

2

你不能。 Android將總是嘗試在您的活動實際加載之前僅使用主題的屬性顯示某些內容。

事實上,correct way to build a splash screen涉及利用這一事實和定製您的主題,使在這段時間顯示的內容您的啓動畫面。

+0

謝謝!正是我在找什麼 – dbalagula23