Android實(shí)現(xiàn)登錄界面的注冊(cè)功能
本文實(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í)有所幫助,也希望大家多多支持腳本之家。
- Android實(shí)現(xiàn)登錄注冊(cè)頁面(上)
- Android實(shí)現(xiàn)登錄注冊(cè)功能
- Android基于Sqlite實(shí)現(xiàn)注冊(cè)和登錄功能
- Android實(shí)現(xiàn)注冊(cè)登錄界面的實(shí)例代碼
- Android設(shè)計(jì)登錄界面、找回密碼、注冊(cè)功能
- Android客戶端實(shí)現(xiàn)注冊(cè)、登錄詳解(1)
- Android登錄注冊(cè)功能 數(shù)據(jù)庫SQLite驗(yàn)證
- Android Studio連接SQLite數(shù)據(jù)庫的登錄注冊(cè)實(shí)現(xiàn)
- Android客戶端實(shí)現(xiàn)注冊(cè)、登錄詳解(2)
- Android實(shí)現(xiàn)登錄注冊(cè)頁面(下)
相關(guān)文章
三種Android單擊事件onclick的實(shí)現(xiàn)方法
這篇文章主要為大家詳細(xì)介紹了三種Android單擊事件onclick的實(shí)現(xiàn)方法,感興趣的小伙伴們可以參考一下2016-05-05appium運(yùn)行各種坑爹報(bào)錯(cuò)問題及解決方法【推薦】
這篇文章主要介紹了 appium運(yùn)行各種坑爹報(bào)錯(cuò)問題及解決方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-06-06Android基于google Zxing實(shí)現(xiàn)各類二維碼掃描效果
這篇文章主要介紹了Android基于google Zxing實(shí)現(xiàn)各類二維碼掃描效果的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-02-02Android中PopuWindow實(shí)現(xiàn)下拉列表實(shí)例
本篇文章主要介紹了Android中PopuWindow實(shí)現(xiàn)下拉列表實(shí)例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07Android開發(fā)手機(jī)無線調(diào)試的方法
今天小編就為大家分享一篇關(guān)于Android開發(fā)手機(jī)無線調(diào)試的方法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2018-12-12Android實(shí)現(xiàn)簡(jiǎn)易的計(jì)算器
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡(jiǎn)易的計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-10-10Android中SwipeBack實(shí)現(xiàn)右滑返回效果
這篇文章主要介紹了Android中SwipeBack實(shí)現(xiàn)右滑返回效果的相關(guān)資料,需要的朋友可以參考下2016-02-02Android開發(fā)使用PopupMenu創(chuàng)建彈出式菜單完整實(shí)例
這篇文章主要介紹了Android開發(fā)使用PopupMenu創(chuàng)建彈出式菜單,結(jié)合完整實(shí)例形式分析了Android基于PopupMenu對(duì)象創(chuàng)建的彈出式菜單相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2019-03-03