成品直播原始碼推薦,登入和註冊兩個頁面的簡單實現

zhibo系統開發發表於2022-04-01

成品直播原始碼推薦,登入和註冊兩個頁面的簡單實現

xml登入介面設計

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
    xmlns:app="
    xmlns:tools="
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
 
    >
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="註冊"
        android:textSize="35sp"
        android:gravity="center"
        android:background="#FF5722"
        />
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="210dp"
    android:orientation="horizontal"
    >
 <Button
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background="@drawable/qq"
     android:layout_weight="1"
     android:text="用QQ註冊"
     android:gravity="center"
     android:textSize="20sp"
     />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="210dp"
        android:background="@drawable/wechat"
        android:layout_weight="1"
        android:text="用微信註冊"
        android:textSize="20sp"
        />
</LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >
        <ImageView
            android:id="@+id/yxlg"
            android:layout_marginTop="12dp"
            android:layout_marginLeft="80dp"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="@drawable/net"
            />
   <TextView
       android:paddingTop="5dp"
       android:paddingBottom="5dp"
       android:id="@+id/yxld"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:text="   用郵箱登入"
       android:gravity="center"
       android:textSize="35sp"
       />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/colorAccent"
        >
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    <TextView
        android:paddingTop="12dp"
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:text="名字:"
        android:gravity="left"
        android:textSize="25sp"
        />
    <EditText
        android:id="@+id/mz"
        android:paddingTop="12dp"
        android:background="@null"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="30sp"
 
        />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/colorAccent"
        >
</LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:paddingTop="12dp"
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:text="賬號:"
            android:gravity="left"
            android:textSize="25sp"
            />
        <EditText
            android:id="@+id/zh"
            android:paddingTop="12dp"
            android:background="@null"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="30sp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/colorAccent"
        >
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:paddingTop="12dp"
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:text="密碼:"
            android:gravity="left"
            android:textSize="25sp"
            />
        <EditText
            android:password="true"
            android:id="@+id/mm"
            android:paddingTop="12dp"
            android:background="@null"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="30sp"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/colorAccent"
        >
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:paddingTop="12dp"
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:text="性別:        "
            android:gravity="left"
            android:textSize="25sp"
            />
        <RadioGroup
            android:id="@+id/xb"
            android:layout_marginTop="15dp"
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        <RadioButton
            android:id="@+id/nan"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="男"
            android:textSize="20sp"
            />
<RadioButton
    android:id="@+id/nu"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="女"
    android:textSize="20sp"
    />
        </RadioGroup>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/colorAccent"
        >
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:paddingTop="12dp"
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:text="選擇你的愛好:"
            android:gravity="left"
            android:textSize="25sp"
            />
        <CheckBox
        android:id="@+id/cg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="唱歌"
        android:textSize="20sp" />
        <CheckBox
            android:id="@+id/tw"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="跳舞"
            android:textSize="20sp" />
        <CheckBox
            android:id="@+id/ds"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="讀書"
            android:textSize="20sp" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/colorAccent"
        >
    </LinearLayout>
    <Button
        android:id="@+id/btn1"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:text="提交"
        android:textSize="30sp"
        />
</LinearLayout>

註冊功能實現

package com.example.registerlogin;
 
import androidx.appcompat.app.AppCompatActivity;
 
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;
 
 
public class MainActivity extends AppCompatActivity implements View.OnClickListener,CompoundButton.OnCheckedChangeListener{
private EditText mz,zh,mm;
private Button btn1;
private String name,id,pwd,sex,hobby;
private RadioGroup xb;
private CheckBox cg,tw,ds;
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn1=findViewById(R.id.btn1);
        mz=findViewById(R.id.mz);
        zh=findViewById(R.id.mz);
        mm=findViewById(R.id.mz);
        cg=findViewById(R.id.cg);
        tw=findViewById(R.id.tw);
        ds=findViewById(R.id.ds);
        xb=findViewById(R.id.xb);
 
        btn1.setOnClickListener(MainActivity.this);
        xb.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
                {switch (checkedId){
                    case R.id.nan:
                    sex = "男";
                    break;
                    case R.id.nu:
                    sex="女";
                    break;
 
                }
                }
            }
        });
    }
    private void getData(){
        name=mz.getText().toString().trim();
        id=zh.getText().toString().trim();
        pwd=mm.getText().toString().trim();
    }
     public void onClick(View v) {
         switch (v.getId()) {
             case R.id.btn1:
                 getData();
 
                 if (TextUtils.isEmpty(name)) {
 
                     Toast.makeText(MainActivity.this, "請輸入名字", Toast.LENGTH_SHORT).show();
                 } else if (TextUtils.isEmpty(id)) {
 
                     Toast.makeText(MainActivity.this, "請輸入賬號", Toast.LENGTH_SHORT).show();
                 } else if (TextUtils.isEmpty(pwd)) {
 
                     Toast.makeText(MainActivity.this, "請輸入密碼", Toast.LENGTH_SHORT).show();
                 } else if (TextUtils.isEmpty(sex)) {
 
                     Toast.makeText(MainActivity.this, "請輸入性別", Toast.LENGTH_SHORT).show();
                 }else if (TextUtils.isEmpty(hobby)) {
 
                     Toast.makeText(MainActivity.this, "請輸入愛好", Toast.LENGTH_SHORT).show();
                 }else {
                     Toast.makeText(MainActivity.this, "註冊成功", Log.i("MainActivity", "檢測到你的註冊資訊:" + "名字:" + name + "  郵箱:" + id + "  性別:" + sex+"  愛好:"+hobby));
                 }
                 break;
         }
     }
 
    public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){
        String motion =buttonView.getText().toString();
        if(isChecked){
            if(!hobby.contains(motion)){
                hobby = hobby + motion;
            }
        }else {
            if(hobby.contains(motion)){
 
              hobby=hobby.replace(motion,"");
            }
 
        }
}
 
}

以上就是 成品直播原始碼推薦,登入和註冊兩個頁面的簡單實現,更多內容歡迎關注之後的文章



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2885360/,如需轉載,請註明出處,否則將追究法律責任。

相關文章