Android实训项目1--注册登录页面

该文描述了一个Android应用的注册页面布局代码,包括用户名、邮箱、密码输入框,性别选择(单选按钮),兴趣爱好(复选框)以及提交按钮。点击提交按钮后,会显示注册成功的提示。此外,还展示了性别选项的选择监听器。
摘要由CSDN通过智能技术生成

实现注册页面登录弹窗 

效果图:

 

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

    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="@android:color/darker_gray">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:gravity="center"
            android:text="@string/zc"
            android:textColor="@android:color/white"/>
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/white"
            />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:orientation="horizontal">
            <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:paddingTop="20dp"
                android:layout_weight="1"
                android:gravity="center_horizontal"
                android:src="@drawable/qq" />
            <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:paddingTop="20dp"
                android:layout_weight="1"
                android:gravity="center_horizontal"
                android:src="@drawable/wechat" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:id="@+id/Rqq"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center_horizontal"
                android:paddingTop="20dp"
                android:paddingBottom="10dp"
                android:textColor="@android:color/white"
                android:textSize="15sp"
                android:text="@string/qqzc" />
            <TextView
                android:id="@+id/Rwx"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center_horizontal"
                android:paddingTop="20dp"
                android:paddingBottom="10dp"
                android:textColor="@android:color/white"
                android:textSize="15sp"
                android:text="@string/wxzc" />
        </LinearLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/white"
            />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="40dp">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="@string/dzyx"
                android:textColor="@android:color/white"
                android:textSize="15sp" />
        </LinearLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/white"
            />
        <!--        横线-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="15dp">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_marginStart="30dp"
                android:textColor="@android:color/white"
                android:text="@string/mingzi"/>

            <EditText
                android:id="@+id/name"
                android:layout_width="400dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginStart="30dp"
                android:autofillHints="name"
                android:inputType="text"
                android:minHeight="48dp"
                android:textColor="@android:color/white"
                tools:ignore="SpeakableTextPresentCheck" />

        </LinearLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/white"
            />
        <!--        横线-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="15dp">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_marginStart="30dp"
                android:textColor="@android:color/white"
                android:text="@string/youxian"/>

            <EditText

                android:id="@+id/email"
                android:layout_width="400dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginStart="30dp"
                android:minHeight="48dp"
                android:textColor="@android:color/white"
                tools:ignore="SpeakableTextPresentCheck" />
        </LinearLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/white"
            />
        <!--        横线-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="15dp">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_marginStart="30dp"
                android:textColor="@android:color/white"
                android:text="@string/mima"/>

            <EditText

                android:id="@+id/password"
                android:layout_width="400dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginStart="30dp"
                android:minHeight="48dp"
                android:textColor="@android:color/white"
                tools:ignore="SpeakableTextPresentCheck" />
        </LinearLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/white"
            />
        <!--        横线-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="15dp">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_marginStart="30dp"
                android:textColor="@android:color/white"
                android:text="@string/xingbie"/>
            <RadioGroup
                android:id="@+id/rdb"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:layout_marginStart="30dp"
                android:orientation="horizontal"
                >

                <RadioButton
                    android:id="@+id/sex1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="30dp"
                    android:textColor="@android:color/white"
                    android:layout_gravity="center"
                    android:text="@string/nan" />
                <RadioButton
                    android:id="@+id/sex2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="30dp"
                    android:textColor="@android:color/white"
                    android:layout_gravity="center"
                    android:text="@string/nv" />
            </RadioGroup>
        </LinearLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/white"
            />
        <!--        横线-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="15dp">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="30dp"
                android:layout_marginTop="10dp"
                android:text="@string/aihao"
                android:textColor="@android:color/white" />
            <CheckBox
                android:id="@+id/hobby1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="30dp"
                android:textColor="@android:color/white"
                android:layout_gravity="center"
                android:text="@string/changge"
                />
            <CheckBox
                android:id="@+id/hobby2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="30dp"
                android:textColor="@android:color/white"
                android:layout_gravity="center"
                android:text="@string/tiaowu"
                />
            <CheckBox
                android:id="@+id/hobby3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="30dp"
                android:textColor="@android:color/white"
                android:layout_gravity="center"
                android:text="@string/dushu"
                />
        </LinearLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/white"
            />
        <!--        横线-->
        <Button
            android:id="@+id/btn_submit"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:text="@string/tijiao"
            android:textColor="@android:color/white"
            android:textSize="18sp"
            />

    </LinearLayout>

</RelativeLayout>
package cn.itcast.register;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    EditText name,email;
    Button btn_submit;
    RadioGroup rdb;
    String a,b;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        name=(EditText)findViewById(R.id.name);
        email=(EditText)findViewById(R.id.email);
        btn_submit= (Button)findViewById(R.id.btn_submit);
        rdb = (RadioGroup) findViewById(R.id.rdb);
        btn_submit.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                a=name.getText().toString();
                b=email.getText().toString();
                Toast.makeText(MainActivity.this, "注册成功",Toast.LENGTH_SHORT).show();
            }
        });
        rdb.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if(i==R.id.sex1) {

                    Toast.makeText(MainActivity.this, "你的性别为男",Toast.LENGTH_SHORT).show();
                }
                else {i=R.id.sex2;Toast.makeText(MainActivity.this, "你的性别为女",Toast.LENGTH_SHORT).show();}
            }
        });

    }
//可继续完善功能
//    private void getData(){
//        name = name.getText().toString().trim();
//
//    }
//    @Override
//    public void onClick(View v){
//        switch (v.getId()){
//            case R.id.name:
//        }
//    }
}

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值