自定义创建一个XML布局

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent">    <TextView        android:layout_width="wrap_content"        android:layout_height="fill_parent"        android:text="请输入VIP账号"        />    <EditText        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:id="@+id/text_vip"        /></LinearLayout>

给Button设置Click事件,将下面代码放入到Click事件中

 AlertDialog.Builder myDialog = new AlertDialog.Builder(MainActivity.this);        final View v = getLayoutInflater().inflate(R.layout.dialoglayout,null);        //创建一个View  去获取刚才自定义创建的XML布局        myDialog.setTitle("自定义的对话框");        myDialog.setView(v);        //把刚才的View设置到myDialog 中        myDialog.setPositiveButton("登录", new DialogInterface.OnClickListener() {            @Override            public void onClick(DialogInterface dialog, int which) {                EditText edt_vip=(EditText)v.findViewById(R.id.text_vip);                //刚才布局中的控件,通过Id进行绑定                if(edt_vip.getText().toString().equals("123456")){                //如果是123456就是会员其他的为普通用户                    ShowMessage("欢迎至尊会员");                }                else{                    ShowMessage("欢迎光临");                }            }        });        myDialog.create().show();        //创建运行

结果:
至尊会员输入123456

点击后

普通用户


点击后

更多相关文章

  1. layout_weight 权重
  2. BaseRecyclerViewAdapterHelper
  3. android:scrollbars属性和弹出键盘的问题
  4. Android布局自定义Shap圆形ImageView,可以单独设置背景与图片
  5. Android(安卓)性能典范:拯救计划
  6. Android第一步
  7. Android(安卓)如何在代码中动态的添加View 及 指定位置
  8. Android(安卓)学习 之 API文档汇总(不断更新)
  9. Android初步

随机推荐

  1. 【 Android(安卓)10 系统启动 】系列 --
  2. android 调色板小练习
  3. Android(安卓)Studio 3.0以上安装apk报错
  4. Android开发小记
  5. java sedevelopment kit not found,Andro
  6. Android(安卓)TextView属性详解
  7. Android开关机动画/铃音是如何播放的?
  8. android 控件list选中后背景变成黑色
  9. Android高手应该精通哪些内容
  10. Android(安卓)的用户层 uevent处理机制