AlertDialog

// 自定义对话框
    private void createcustomChoiceDialog() {
        AlertDialog.Builder builder = new Builder(MainActivity.this);
        builder.setTitle("自定义对话框!");
        // 设置自定义布局
        View v = LayoutInflater.from(MainActivity.this).inflate(
                R.layout.activity_custom, null);
 
        builder.setView(v);
        dialog = builder.create();
        // 显示
        dialog.show();
        editixt = (EditText) v.findViewById(R.id.editText1);
        but_deng = (Button) v.findViewById(R.id.but_deng);

        but_deng.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                String name = editixt.getText().toString();
                Log.d("zzz", name);
                Toast.makeText(MainActivity.this, name, 0).show();
                dialog.dismiss();
                                  
            
                
            
            }
        });
        

    }



-------------------------------------------------------------------------------------

//自定义的视图文件




<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="34dp"
        android:layout_marginTop="28dp"
        android:text="用户名" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView1"
        android:layout_toRightOf="@+id/textView1"
        android:ems="10"
        android:inputType="textPersonName" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="40dp"
        android:text="密码" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView2"
        android:layout_alignBottom="@+id/textView2"
        android:layout_alignLeft="@+id/editText1"
        android:ems="10"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/but_deng"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView2"
        android:layout_below="@+id/editText2"
        android:layout_marginTop="50dp"
        android:text="登录" />

    <Button
        android:id="@+id/but_zhuce"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/but_deng"
        android:layout_alignBottom="@+id/but_deng"
        android:layout_marginLeft="64dp"
        android:layout_toRightOf="@+id/but_deng"
        android:text="注册" />

</RelativeLayout>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值