zoukankan      html  css  js  c++  java
  • Android 实现闪屏页和右上角的倒计时跳转

    效果图:

    闪屏页用到了handler和CountDownTimer类,还需配置一下Activity的主题,这里是:android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 全屏主题的意思。

    实现源码:

    package com.example.shanping;
    
    import java.lang.ref.WeakReference;
    
    import com.example.shanping.MyActivity.MyCountDownTimer;
    
    import android.os.Bundle;
    import android.os.CountDownTimer;
    import android.os.Handler;
    import android.os.Message;
    import android.app.Activity;
    import android.content.Intent;
    import android.util.Log;
    import android.view.Menu;
    import android.widget.TextView;
    
    public class MainActivity extends Activity {
    
        private MyCountDownTimer mc; 
        private TextView tv;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tv = (TextView) findViewById(R.id.textView1); 
            mc = new MyCountDownTimer(3000, 1000); 
            mc.start();
            handler.postDelayed(new Runnable() {
                
                @Override
                public void run() {
                    Intent intent=new Intent(MainActivity.this,MyActivity.class);
                    startActivity(intent);
                }
            }, 3000);
        }
        private Handler handler=new Handler();
        /** 
           * 继承 CountDownTimer 防范 
           * 
           * 重写 父类的方法 onTick() 、 onFinish() 
           */
          
          class MyCountDownTimer extends CountDownTimer { 
            /** 
             * 
             * @param millisInFuture 
             *      表示以毫秒为单位 倒计时的总数 
             * 
             *      例如 millisInFuture=1000 表示1秒 
             * 
             * @param countDownInterval 
             *      表示 间隔 多少微秒 调用一次 onTick 方法 
             * 
             *      例如: countDownInterval =1000 ; 表示每1000毫秒调用一次onTick() 
             * 
             */
            public MyCountDownTimer(long millisInFuture, long countDownInterval) { 
              super(millisInFuture, countDownInterval); 
            } 
          
            public void onFinish() { 
              tv.setText("正在跳转"); 
            } 
          
            public void onTick(long millisUntilFinished) { 
              tv.setText("倒计时(" + millisUntilFinished / 1000 + ")"); 
            } 
    
          }
        
    }
  • 相关阅读:
    建立文件结构
    PCL类的设计结构
    如何编写新的PCL类
    PCL推荐的命名规范(2)
    PCL推荐的命名规范(1)
    PCL中异常处理机制
    如何增加新的PointT类型
    hdoj 1728 逃离迷宫
    ny710 外星人的供给站
    ny714 Card Trick
  • 原文地址:https://www.cnblogs.com/hyyweb/p/5208865.html
Copyright © 2011-2022 走看看