登录屏幕与Toast一起闪烁

时间:2010-08-04 10:44:29

标签: android

我创建了一个登录屏幕,但在登录屏幕出现之前我想要一个图像在屏幕上闪烁。为此,我使用Toast。 但问题是在闪烁之前,图像登录屏幕出现一段时间后图像闪烁,然后再次出现登录屏幕。我希望在屏幕上出现任何内容之前先闪现图像。这是我的代码:

    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 个答案:

答案 0 :(得分:1)

你需要使用Handler类来保持当前的LoginWindow几秒钟,Handler Class提供了一种方法,可以在显示屏幕之前显示图像,

如果使用Handler方法是不可能的话那么请使用像OnStart()等的Activity LifeCycle方法,你可以使用很多活动方法

以下是一些有用的代码...

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 ...");
}

}

相关问题