目前在我的应用程序中,当用户单击按钮或移动到新的活动时,我将显示广告,我想做的是在加载广告之前通知用户。我想显示消息,如广告正在加载.!和2-3秒后,味精应该消失。简而言之,我想在广告的预加载上显示对话框。我尝试使用警告信息,但这不起作用,我不知道我们需要在哪里添加警报对话框。
请帮帮.!
提前谢谢.!
发布于 2020-02-12 19:12:55
我通过使用以下代码实现了这一点
/* Show your dialog */
ShowDailog();
/* following code will run after 3000ms */
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
showInterstitial();
}
}, 3000);发布于 2020-01-12 12:56:09
您可以使用一个倒数x秒的Thread,每秒钟textView都会改变(这将是一个数字),然后用户就会有倒计时的感觉。
public CountDownThread extend Thread {
private int mTotalNum;
private CountDownListener mCuntDownListener;
public CountDownThread(int totalNum, CountDownListener countDownListener) {
this.mTotalNum = totalNum
this.mCountDownListener = countDownListener
}
@Override
public void run(){
while (mTotalNum > 0) {
try {
sleep(1000);
}catch (InterruptedException e){
//
}
--mTotalNum
}
mCuntDownListener.onCountDownThreadDone()
}在你的活动中:
1)您需要实现CountDownListener (当您实现CountDownListener时,您必须实现onCountDownThreadDone()方法,在那里您需要实现您的dailog box)。
2)此外,您还需要调用CountDownThread(3, this) (3是您的显示时间(秒),this是侦听器)。
这是interface
public interface CountDownListener {
void onCountDownThreadDone();
}在计数结束(在您的例子中是3秒)之后,将调用onCountDownThreadDone()方法(查看CountDownThread类中的run()方法)。然后将出现dailog box的实现(在Activity中实现它)。
发布于 2020-01-12 13:16:15
您可以使用如下所示的CountDownTimer,首先,吐司消息显示,然后3秒。(3000毫秒)稍后,您的广告代码将运行。
Toast.makeText(this, "Ad is loading...", Toast.LENGTH_LONG).show();
new CountDownTimer(3000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() { // runs after 2 sec. (2000 msec.)
// This is the place where you call your interstitial ad.
}
}.start();https://stackoverflow.com/questions/59703848
复制相似问题