如何显示片段几秒钟并隐藏它?
问题描述:
我想实现一个片段作为启动画面,它会显示不到1秒,它会用自己的插页式广告取而代之。我想实施Admob建议的展示插页式广告的方式。我希望在片段内显示'应用加载'屏幕,并在广告准备就绪时隐藏片段。我正在做一个片段而不是一个视图,因为我需要使这个通用的解决方案,然后将其添加到我的其他应用程序以及。如何显示片段几秒钟并隐藏它?
答
进入您的插页式广告的OnCreate把这段代码
// This time is in milliseconds
final int SPLASH_TIME_OUT = 3000;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// Code to start new activity and finish this one
}
}, SPLASH_TIME_OUT);
答
您可以显示一个片段和您的片段交易后,您可以添加
private static int SPLASH_TIME_OUT = 3000;
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo/company
*/
@Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
答
试试这个代码
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// your code here
}
}, TIME_OUT_IN_MILLIS);
无关,但这是一个强大的卸载驱动程序,你在做什么。 – njzk2