使用 android 处理程序的启动画面不工作
splash screen using android handler is not working
我的启动画面不工作。
它只是闪烁一个空布局 2 秒并加载 mainactivity ...
我已经从 drawable 添加了一个 png 图像作为初始屏幕的 android:background。
但它不显示图像..
我也试过在启动画面中使用文本字段,但它再次显示一个空布局..
这是我的初始屏幕活动代码
public class SplashScreenActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_splash_screen);
//Handler handler = new Handler();
// run a thread after 2 seconds to start the home screen
//handler.postDelayed(new Runnable() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// make sure we close the splash screen so the user won't come
// back when it presses back key
finish();
// start the home screen
Intent intent = new Intent(SplashScreenActivity.this,
MainMenuActivity.class);
startActivity(intent);
}
}, 2000); // time in milliseconds (1 second = 1000 milliseconds) until
// the run() method will be called
}
}
这是我的初始屏幕代码,它正在运行:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
int SPLASH_TIME_OUT = 1500;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashScreenActivity.this, DrawerActivity.class));
finish();
}
}, SPLASH_TIME_OUT);
}
试试看
我的启动画面不工作。 它只是闪烁一个空布局 2 秒并加载 mainactivity ... 我已经从 drawable 添加了一个 png 图像作为初始屏幕的 android:background。 但它不显示图像.. 我也试过在启动画面中使用文本字段,但它再次显示一个空布局..
这是我的初始屏幕活动代码
public class SplashScreenActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_splash_screen);
//Handler handler = new Handler();
// run a thread after 2 seconds to start the home screen
//handler.postDelayed(new Runnable() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// make sure we close the splash screen so the user won't come
// back when it presses back key
finish();
// start the home screen
Intent intent = new Intent(SplashScreenActivity.this,
MainMenuActivity.class);
startActivity(intent);
}
}, 2000); // time in milliseconds (1 second = 1000 milliseconds) until
// the run() method will be called
}
}
这是我的初始屏幕代码,它正在运行:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
int SPLASH_TIME_OUT = 1500;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashScreenActivity.this, DrawerActivity.class));
finish();
}
}, SPLASH_TIME_OUT);
}
试试看