2010-08-04 48 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 ..."); 
} 

}