我创建了一个登录屏幕,但在登录屏幕出现之前,我想要一张图片在屏幕上闪烁。为此,我使用 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);
谢谢 迪帕克
最佳答案
你需要使用 Handler 类来保持当前的 LoginWindow 几秒钟,Handler 类提供了一个方法,可以在屏幕显示之前使用显示图像,
如果无法使用 Handler 方法,请使用 Activity 生命周期方法,如 OnStart() 等,您可以使用很多 Activity 方法
这里有一些有用的代码给你..
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 ...");
}
关于android - 登录屏幕闪烁 Toast,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3404724/