2010-08-04 83 views
3

我創建了一個登錄屏幕,但在登錄屏幕出現之前,我想讓圖像在屏幕上閃爍。爲此,我使用吐司。 但問題是在閃爍圖像登錄屏幕出現一段時間之前,圖像閃爍後再次出現登錄屏幕。在屏幕上出現任何內容之前,我想先閃爍圖像。這裏是我的代碼:登錄屏幕閃爍吐司

setContentView(R.layout.main); 


    ImageView iv = new ImageView(this); 
    iv.setImageDrawable(getResources().getDrawable(R.drawable.start)); 

    Toast t = new Toast(this); 
    t.setView(iv); 
    t.show(); 
    t.setDuration(5); 

感謝 迪帕克

回答

1

你需要使用處理程序類來保存幾秒鐘本登錄窗口,處理類提供了可用於顯示圖像的屏幕之前顯示的方法,

如果是不可能的處理方法,那麼請使用類似的OnStart)活動的生命週期方法(等也有很多活動方法ü可以使用

下面是一些有用的代碼到u。 。

private Handler handler; 
private final static String DEBUG_TAG = "splashScreen"; 


public void onCreate(Bundle savedInstanceState) { 
    Log.i(DEBUG_TAG, "onCreate executes ..."); 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splashscr); 
    handler = new Handler(); 




} 


public void onResume() 
{ Log.i(DEBUG_TAG, "onResume executes ..."); 
handler.postDelayed(new Runnable() 
{ 

    public void run() 
    { 
     Intent myIntent= new Intent(SplashScreen.this,TabCls.class); 
     startActivity(myIntent);  
    } 
}, 1000); 

super.onResume(); 
} 


protected void onStart() 
{ 
    super.onStart(); 
    Log.i(DEBUG_TAG, "onStart executes ..."); 
} 




protected void onRestart() 
{ 
    super.onRestart(); 
    Log.i(DEBUG_TAG, "onRestart executes ..."); 
} 



protected void onPause() 
{ 
    super.onPause(); 
    Log.i(DEBUG_TAG, "onPause executes ..."); 

} 


protected void onStop() 
{ 
    super.onStop(); 
    Log.i(DEBUG_TAG, "onStop executes ..."); 
}  

protected void onDestroy() 
{ 

    super.onDestroy(); 

    Log.i(DEBUG_TAG, "onDestroy executes ..."); 
} 

}