CountDownTimer
类。这个类提供了一个简单的方法来创建倒计时。创建一个CountDownTimer
对象,指定总时间(以毫秒为单位)和每个周期的时间间隔。重写onTick()
方法和onFinish()
方法,分别处理每秒更新和倒计时结束时的逻辑。调用start()
方法启动倒计时。ImageView
来显示广告图片,并结合Handler
或CountDownTimer
来实现倒计时功能。以下是一个简单的示例:,,``java,public class SplashScreenActivity extends AppCompatActivity {,, private ImageView adImageView;, private TextView countDownTextView;, private CountDownTimer countDownTimer;,, @Override, protected void onCreate(Bundle savedInstanceState) {, super.onCreate(savedInstanceState);, setContentView(R.layout.activity_splash_screen);,, adImageView = findViewById(R.id.ad_image_view);, countDownTextView = findViewById(R.id.count_down_text_view);,, // Load the ad image, Glide.with(this).load("https://your-ad-image-url.com").into(adImageView);,, // Start the countdown timer for 5 seconds, countDownTimer = new CountDownTimer(5000, 1000) {, @Override, public void onTick(long millisUntilFinished) {, countDownTextView.setText("Loading... " + millisUntilFinished / 1000);, },, @Override, public void onFinish() {, Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);, startActivity(intent);, finish();, }, };, countDownTimer.start();, },, @Override, protected void onDestroy() {, super.onDestroy();, if (countDownTimer != null) {, countDownTimer.cancel();, }, },},
`,,在这个示例中,我们使用了
Glide库来加载广告图片,并使用
CountDownTimer`来实现倒计时功能。当倒计时结束时,跳转到主界面(MainActivity)。请根据你的实际需求修改广告图片的URL和倒计时时间。Powered By Z-BlogPHP 1.7.3