zoukankan      html  css  js  c++  java
  • android 弹出窗口

    1. xml 文件

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
        Android:orientation="vertical"
        Android:layout_width="fill_parent"
        Android:layout_height="fill_parent"
        >
    <Button Android:id="@+id/alert"
            Android:layout_width="fill_parent"
            Android:layout_height="wrap_content"
            Android:text="Make an alert"></Button>
    <Button    Android:id="@+id/toast"
            Android:layout_width="fill_parent"
            Android:layout_height="wrap_content"
            Android:text="Make a toast"></Button>
    </LinearLayout>

    2. 源文件

     package a06.test;

    import android.app.Activity;
    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.Toast;

    public class a06 extends Activity {
        //定义变量
        private Button alert = null;
        private Button toast = null;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            System.out.println("郑文亮");
            //根据Id得到控件对象
            alert = (Button)findViewById(R.id.alert);
            toast = (Button)findViewById(R.id.toast);
          
            //给按钮设定单击事件监听器
            alert.setOnClickListener(new View.OnClickListener() {
              
                @Override
                public void onClick(View v) {
                    //显示AlertDialog
                    new AlertDialog.Builder(a06.this).setTitle("弹出例子").setMessage("您的信息").setNeutralButton("close01", new DialogInterface.OnClickListener() {
                      
                        //点击AlertDialog上的按钮的事件处理代码
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            System.out.println("郑文亮");
                          
                        }
                    }).show();
                  
                }
            });
            toast.setOnClickListener(new View.OnClickListener() {
              
                //显示Toast
                @Override
                public void onClick(View v) {
              
                    Toast.makeText(a06.this, "<看到我了吗?一会我就消失了>", Toast.LENGTH_SHORT).show();
                  
                }
            });
        }
    }

  • 相关阅读:
    面向对象进阶
    EasyDSS转码模块关于gRPC服务注册到ETCD的实现过程
    如何通过ETCD实现EasyDSS分布式负载均衡?ETCD部署方案
    EasyDSS_dash版本如何在新内核下实现rtsp源地址的分发?
    EasyDSS因为系统时间导致的闪退分析及处理
    EasyScreenLive推流组件推RTSP流到EasyDSS操作过程分享
    【解决方案】无人机+EasyDSS实现直播推流警务安防类行业应用
    EasyDSS转码服务负载均衡采用grpc balance回报找不到结构体问题排查及修复
    EasyDSS视频直播时直播间接口和实际接口为什么会存在差异?
    在线课堂EasyDSS_dash版本虚拟直播RTSP播放无视频流问题
  • 原文地址:https://www.cnblogs.com/zhwl/p/2110302.html
Copyright © 2011-2022 走看看