欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實(shí)現(xiàn)登錄界面的注冊(cè)功能

 更新時(shí)間:2022年04月23日 17:12:43   作者:DY.memory  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)登錄界面的注冊(cè)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android登錄界面的注冊(cè)實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下

注冊(cè)一個(gè)登錄界面在控制臺(tái)將輸入的信息文本選框展示出來

xml界面設(shè)計(jì)(前面已發(fā))

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
?
? ? >
? ? <TextView
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="注冊(cè)"
? ? ? ? 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注冊(cè)"
? ? ?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="用微信注冊(cè)"
? ? ? ? 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="賬號(hào):"
? ? ? ? ? ? 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>

注冊(cè)功能實(shí)現(xiàn)

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, "請(qǐng)輸入名字", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? ?} else if (TextUtils.isEmpty(id)) {
?
? ? ? ? ? ? ? ? ? ? ?Toast.makeText(MainActivity.this, "請(qǐng)輸入賬號(hào)", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? ?} else if (TextUtils.isEmpty(pwd)) {
?
? ? ? ? ? ? ? ? ? ? ?Toast.makeText(MainActivity.this, "請(qǐng)輸入密碼", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? ?} else if (TextUtils.isEmpty(sex)) {
?
? ? ? ? ? ? ? ? ? ? ?Toast.makeText(MainActivity.this, "請(qǐng)輸入性別", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? ?}else if (TextUtils.isEmpty(hobby)) {
?
? ? ? ? ? ? ? ? ? ? ?Toast.makeText(MainActivity.this, "請(qǐng)輸入愛好", Toast.LENGTH_SHORT).show();
? ? ? ? ? ? ? ? ?}else {
? ? ? ? ? ? ? ? ? ? ?Toast.makeText(MainActivity.this, "注冊(cè)成功", Log.i("MainActivity", "檢測(cè)到你的注冊(cè)信息:" + "名字:" + 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,"");
? ? ? ? ? ? }
?
? ? ? ? }
}
?
}

我沒有輸入愛好,所以控制臺(tái)輸出null

這個(gè)代碼較簡(jiǎn)單,xml用到的都是一些簡(jiǎn)單的線性布局,和一些對(duì)控件位置和id的改動(dòng),定義,Java文件用的是對(duì)xml控件的獲取和輸出,展示!

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論