您好,欢迎来到源码搜藏!分享精神,快乐你我!提示:担心找不到本站?在百度搜索“源码搜藏”,网址永远不丢失!
  • 首 页
  • 在线工具
  • jquery手册
  • 当前位置:首页 > 安卓源码 > 技术博客 >

    Android对话框出现4秒后自动消失的代码实现

    时间:2017-09-25 15:16 来源:互联网 作者:源码搜藏 浏览:收藏 挑错 推荐 打印

    [代码]的Java代码: ? 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 public class MainActivity extends AppCompatActivity { private But

    [代码]的Java代码:

    ?
    01
    02
    03
    04
    05
    06
    07
    08
    09
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    public class MainActivity extends AppCompatActivity {
     
        private Button dialog1,dialog2;
        private AlertDialog alert;
        private Timer timerl;
        private MyHandler handler;
     
     
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
     
            setContentView(R.layout.activity_main);
            
            timerl=new Timer();
            handler=new MyHandler();
            
            dialog1=(Button)findViewById(R.id.dialog1);
            dialog1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    showAlertDialog();
                }
            });
     
     
        }
     
        private void showAlertDialog(){
            AlertDialog.Builder builder=new AlertDialog(this);
            builder.setTitle("confirm!");
            builder.setMessage("welcome to use~");
            builder.setCancelable(false);
            alert=builder.create();
            alert.show();
     
            timerl.schedule(new CloseDialogTask(),4000);
        }
        
        private class CloseDialogTask extends TimerTask
        {
         private void run(){
             handler.sendEmptyMessage(0);
         }  
        }
        
        private class MyHandler extends Handler{
            public void handleMessage(Message msg){
                alert.dismiss();
            }
        }

    Android对话框出现4秒后自动消失的代码实现转载http://www.codesocang.com/appboke/36627.html
    标签:网站源码