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

    效果图:

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

    实现源码:

     1 package com.example.shanping;
     2 
     3 import java.lang.ref.WeakReference;
     4 
     5 import com.example.shanping.MyActivity.MyCountDownTimer;
     6 
     7 import android.os.Bundle;
     8 import android.os.CountDownTimer;
     9 import android.os.Handler;
    10 import android.os.Message;
    11 import android.app.Activity;
    12 import android.content.Intent;
    13 import android.util.Log;
    14 import android.view.Menu;
    15 import android.widget.TextView;
    16 
    17 public class MainActivity extends Activity {
    18 
    19     private MyCountDownTimer mc; 
    20     private TextView tv;
    21     @Override
    22     protected void onCreate(Bundle savedInstanceState) {
    23         super.onCreate(savedInstanceState);
    24         setContentView(R.layout.activity_main);
    25         tv = (TextView) findViewById(R.id.textView1); 
    26         mc = new MyCountDownTimer(3000, 1000); 
    27         mc.start();
    28         handler.postDelayed(new Runnable() {
    29             
    30             @Override
    31             public void run() {
    32                 Intent intent=new Intent(MainActivity.this,MyActivity.class);
    33                 startActivity(intent);
    34             }
    35         }, 3000);
    36     }
    37     private Handler handler=new Handler();
    38     /** 
    39        * 继承 CountDownTimer 防范 
    40        * 
    41        * 重写 父类的方法 onTick() 、 onFinish() 
    42        */
    43       
    44       class MyCountDownTimer extends CountDownTimer { 
    45         /** 
    46          * 
    47          * @param millisInFuture 
    48          *      表示以毫秒为单位 倒计时的总数 
    49          * 
    50          *      例如 millisInFuture=1000 表示1秒 
    51          * 
    52          * @param countDownInterval 
    53          *      表示 间隔 多少微秒 调用一次 onTick 方法 
    54          * 
    55          *      例如: countDownInterval =1000 ; 表示每1000毫秒调用一次onTick() 
    56          * 
    57          */
    58         public MyCountDownTimer(long millisInFuture, long countDownInterval) { 
    59           super(millisInFuture, countDownInterval); 
    60         } 
    61       
    62         public void onFinish() { 
    63           tv.setText("正在跳转"); 
    64         } 
    65       
    66         public void onTick(long millisUntilFinished) { 
    67           tv.setText("倒计时(" + millisUntilFinished / 1000 + ")"); 
    68         } 
    69 
    70       }
    71     
    72 }
  • 相关阅读:
    leetcode 268. Missing Number
    DBSCAN
    python二维数组初始化
    leetcode 661. Image Smoother
    leetcode 599. Minimum Index Sum of Two Lists
    Python中的sort() key含义
    leetcode 447. Number of Boomerangs
    leetcode 697. Degree of an Array
    滴滴快车奖励政策,高峰奖励,翻倍奖励,按成交率,指派单数分级(1月3日)
    北京Uber优步司机奖励政策(1月2日)
  • 原文地址:https://www.cnblogs.com/ganchuanpu/p/8457399.html
Copyright © 2011-2022 走看看