zoukankan      html  css  js  c++  java
  • Android:自定义对话框

    项目名称:dev.sky.android.CustomDialog

    自定义一个登录对话框:

    Xml文件:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation
    ="vertical"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content">
    <TextView
    android:text="用户名"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content"
    android:textSize
    ="20sp"
    />
    <EditText
    android:layout_width="fill_parent"
    android:layout_height
    ="wrap_content"
    android:id
    ="@+id/user"
    />
    <TextView
    android:layout_width="wrap_content"
    android:layout_height
    ="wrap_content"
    android:text
    ="密码"
    android:textSize
    ="20sp"
    />
    <EditText
    android:id="@+id/password"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="wrap_content"
    android:password
    ="true"
    />
    </LinearLayout>

      CutomDialogActivity.java

    package dev.sky.android.custom_dialog;

    import android.app.Activity;
    import android.app.AlertDialog;
    import android.app.AlertDialog.Builder;
    import android.app.Dialog;
    import android.app.ProgressDialog;
    import android.content.DialogInterface;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;

    publicclass CustomDialogActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    publicvoid onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    showDialog(
    0);
    }

    @Override
    protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder builder
    =new AlertDialog.Builder(this);
    AlertDialog customDialog;

    LayoutInflater inflater
    = getLayoutInflater();
    View layout
    = inflater.inflate(R.layout.custom, null);
    builder.setTitle(
    "登录");
    builder.setView(layout);
    builder.setPositiveButton(
    "登录", new DialogInterface.OnClickListener() {
    publicvoid onClick(DialogInterface arg0, int arg1) {
    mProgress
    = ProgressDialog.show(CustomDialogActivity.this,"" , "正在登录");

    // 新线程,睡眠3秒然后关闭ProgressDialog
    new Thread() {
    publicvoid run() {
    try {
    sleep(
    3000);
    }
    catch (InterruptedException e) {
    e.printStackTrace();
    }
    finally {
    mProgress.dismiss();
    }
    }
    }.start();
    }
    });
    builder.setNegativeButton(
    "取消", new DialogInterface.OnClickListener() {

    @Override
    publicvoid onClick(DialogInterface arg0, int arg1) {
    CustomDialogActivity.
    this.finish();
    }
    });
    customDialog
    = builder.create();

    return customDialog;
    }
    private ProgressDialog mProgress;
    }

      

  • 相关阅读:
    MySQL 待解决死锁
    MySQL5.7 服务 crash 后无法启动
    MySQL Group Replication
    MySQL容量规划之tcpcopy应用之道
    Python模块安装路径初探
    MySQL5.7多源复制实践
    Mysql中两个select语句的连接
    ThinkPhp sql语句执行方法
    TP框架如何绑定参数。目的进行ajax验证
    jquery 复合事件 toggle()方法的使用
  • 原文地址:https://www.cnblogs.com/skyhacker/p/2138592.html
Copyright © 2011-2022 走看看