android實現(xiàn)注冊頁面開發(fā)
本文實例為大家分享了android實現(xiàn)注冊頁面開發(fā)的具體代碼,供大家參考,具體內(nèi)容如下
在values文件里創(chuàng)建以下幾個文件
colors代碼:
<?xml version="1.0" encoding="utf-8"?> <resources> ? ? <color name="purple_200">#FFBB86FC</color> ? ? <color name="purple_500">#FF6200EE</color> ? ? <color name="purple_700">#FF3700B3</color> ? ? <color name="teal_200">#FF03DAC5</color> ? ? <color name="teal_700">#FF018786</color> ? ? <color name="black">#FF000000</color> ? ? <color name="white">#FFFFFFFF</color> </resources>
strings代碼塊
<resources> ? ? <string name="app_name">19260234anzidawang</string> </resources>
修改為自己的學(xué)號
styles代碼
<?xml version="1.0" encoding="utf-8"?> <resources> ? ? <style name="hLine"> ? ? ? ? <item name="android:layout_width">match_parent</item> ? ? ? ? <item name="android:layout_height">1dp</item> ? ? ? ? <item name="android:background">@android:color/white</item> ? ? </style> ? ? <style name="vLine"> ? ? ? ? <item name="android:layout_width">1dp</item> ? ? ? ? <item name="android:layout_height">match_parent</item> ? ? ? ? <item name="android:background">@android:color/white</item> ? ? </style> ? ? <style name="tvone"> ? ? ? ? <item name="android:layout_height">match_parent</item> ? ? ? ? <item name="android:layout_width">0dp</item> ? ? ? ? <item name="android:layout_weight">1</item> ? ? ? ? <item name="android:drawablePadding">8dp</item> ? ? ? ? <item name="android:gravity">center_horizontal</item> ? ? ? ? <item name="android:paddingTop">40dp</item> ? ? ? ? <item name="android:textColor">@android:color/white</item> ? ? ? ? <item name="android:textSize">15dp</item> ? ? </style> ? ? <style name="tvtwo"> ? ? ? ? <item name="android:layout_width">wrap_content</item> ? ? ? ? <item name="android:layout_height">wrap_content</item> ? ? ? ? <item name="android:layout_marginLeft">20dp</item> ? ? ? ? <item name="android:textColor">@android:color/white</item> ? ? ? ? <item name="android:textSize">15dp</item> ? ? </style> ? ? <style name="etOne"> ? ? ? ? <item name="android:layout_width">match_parent</item> ? ? ? ? <item name="android:layout_height">wrap_content</item> ? ? ? ? <item name="android:layout_marginLeft">30dp</item> ? ? ? ? <item name="android:background">@null</item> ? ? ? ? <item name="android:textColor">@android:color/white</item> ? ? </style> </resources>
布局文件(activity_main)
<?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:background="@drawable/register_bg"> ? ? <LinearLayout ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="match_parent" ? ? ? ? android:orientation="vertical"> ? ? ? ? <TextView ? ? ? ? ? ? android:id="@+id/tv_title" ? ? ? ? ? ? android:layout_width="match_parent" ? ? ? ? ? ? android:layout_height="50dp" ? ? ? ? ? ? android:background="#01ceff" ? ? ? ? ? ? android:gravity="center" ? ? ? ? ? ? android:text="注冊" ? ? ? ? ? ? android:textColor="@color/white" ? ? ? ? ? ? android:textSize="20sp"/> ? ? ? ? <LinearLayout ? ? ? ? ? ? android:layout_width="match_parent" ? ? ? ? ? ? android:layout_height="130dp" ? ? ? ? ? ? android:orientation="horizontal"> ? ? ? ? ? ? <TextView ? ? ? ? ? ? ? ? style="@style/tvone" ? ? ? ? ? ? ? ? android:drawableTop="@drawable/qq_icon" ? ? ? ? ? ? ? ? android:text="qq register"/> ? ? ? ? ? ? <View style="@style/vLine"/> ? ? ? ? ? ? <TextView ? ? ? ? ? ? ? ? style="@style/tvone" ? ? ? ? ? ? ? ? android:drawableTop="@drawable/weixin_icon" ? ? ? ? ? ? ? ? android:text="wechat register"/> ? ? ? ? </LinearLayout> ? ? ? ? <View style="@style/hLine"/> ? ? ? ? <LinearLayout ? ? ? ? ? ? android:layout_width="match_parent" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:gravity="center" ? ? ? ? ? ? android:orientation="horizontal" ? ? ? ? ? ? android:padding="15dp"> ? ? ? ? ? ? <ImageView ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="match_parent" ? ? ? ? ? ? ? ? android:src="@drawable/email_icon"/> ? ? ? ? ? ? <TextView ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="match_parent" ? ? ? ? ? ? ? ? android:layout_marginLeft="15dp" ? ? ? ? ? ? ? ? android:text="use email register" ? ? ? ? ? ? ? ? android:textColor="@android:color/white" ? ? ? ? ? ? ? ? android:textSize="15sp"/> ? ? ? ? </LinearLayout> ? ? ? ? <View style="@style/hLine" /> ? ? ? ? <LinearLayout ? ? ? ? ? ? android:layout_width="match_parent" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:orientation="horizontal" ? ? ? ? ? ? android:padding="15dp"> ? ? ? ? ? ? <TextView ? ? ? ? ? ? ? ? style="@style/tvtwo" ? ? ? ? ? ? ? ? android:text="name"/> ? ? ? ? ? ? <EditText ? ? ? ? ? ? ? ? android:id="@+id/et_name" ? ? ? ? ? ? ? ? style="@style/etOne"/> ? ? ? ? </LinearLayout> ? ? ? ? <View style="@style/hLine"/> ? ? ? ? <LinearLayout ? ? ? ? ? ? android:layout_width="match_parent" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:orientation="horizontal" ? ? ? ? ? ? android:padding="15dp"> ? ? ? ? ? ? <TextView ? ? ? ? ? ? ? ? style="@style/tvtwo" ? ? ? ? ? ? ? ? android:text="email"/> ? ? ? ? ? ? <EditText ? ? ? ? ? ? ? ? android:id="@+id/et_mail" ? ? ? ? ? ? ? ? style="@style/etOne"/> ? ? ? ? </LinearLayout> ? ? ? ? <View style="@style/hLine"/> ? ? ? ? <LinearLayout ? ? ? ? ? ? android:layout_width="match_parent" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:orientation="horizontal" ? ? ? ? ? ? android:padding="15dp"> ? ? ? ? ? ? <TextView ? ? ? ? ? ? ? ? style="@style/tvtwo" ? ? ? ? ? ? ? ? android:text="password"/> ? ? ? ? ? ? <EditText ? ? ? ? ? ? ? ? android:id="@+id/et_pwd" ? ? ? ? ? ? ? ? style="@style/etOne" ? ? ? ? ? ? ? ? android:inputType="textPassword"/> ? ? ? ? </LinearLayout> ? ? ? ? <View ?style="@style/hLine"/> ? ? ? ? <LinearLayout ? ? ? ? ? ? android:layout_width="match_parent" ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? android:orientation="horizontal" ? ? ? ? ? ? android:padding="15dp"> ? ? ? ? ? ? <TextView ? ? ? ? ? ? ? ? style="@style/tvtwo" ? ? ? ? ? ? ? ? android:text="glender"/> ? ? ? ? ? ? ? ? <RadioGroup ? ? ? ? ? ? ? ? ? ? android:id="@+id/rg_sex" ? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent" ? ? ? ? ? ? ? ? ? ? android:layout_height="match_parent" ? ? ? ? ? ? ? ? ? ? android:layout_marginLeft="50dp" ? ? ? ? ? ? ? ? ? ? android:orientation="horizontal"> ? ? ? ? ? ? ? ? ? ? <RadioButton ? ? ? ? ? ? ? ? ? ? ? ? android:id="@+id/rb_boy" ? ? ? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? ? ? ? ? android:text="man" ? ? ? ? ? ? ? ? ? ? ? ? android:textColor="@android:color/white" ? ? ? ? ? ? ? ? ? ? ? ? android:textSize="15sp"/> ? ? ? ? ? ? ? ? <RadioButton ? ? ? ? ? ? ? ? ? ? android:id="@+id/rb_girl" ? ? ? ? ? ? ? ? ? ? style="@style/tvtwo" ? ? ? ? ? ? ? ? ? ? android:text="woman"/> ? ? ? ? ? ? ? ? </RadioGroup> ? ? ? ? </LinearLayout> ? ? ? ? <View style="@style/hLine"/> ? ? ? ? <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:text="chose your hobby" ? ? ? ? ? ? ? ? android:textColor="@android:color/white" ? ? ? ? ? ? ? ? android:textSize="15sp"/> ? ? ? ? ? ? <CheckBox ? ? ? ? ? ? ? ? android:id="@+id/cb_sing" ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? android:text="sing" ? ? ? ? ? ? ? ? android:textColor="@android:color/white" ? ? ? ? ? ? ? ? android:textSize="15sp"/> ? ? ? ? ? ? <CheckBox ? ? ? ? ? ? ? ? android:id="@+id/cb_dance" ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? android:text="dancing" ? ? ? ? ? ? ? ? android:textColor="@android:color/white" ? ? ? ? ? ? ? ? android:textSize="15sp"/> ? ? ? ? ? ? <CheckBox ? ? ? ? ? ? ? ? android:id="@+id/cb_read" ? ? ? ? ? ? ? ? android:layout_width="wrap_content" ? ? ? ? ? ? ? ? android:layout_height="wrap_content" ? ? ? ? ? ? ? ? android:text="read" ? ? ? ? ? ? ? ? android:textColor="@android:color/white" ? ? ? ? ? ? ? ? android:textSize="15sp"/> ? ? ? ? </LinearLayout> ? ? ? ? <View style="@style/hLine"/> ? ? <View ? ? ? ? android:id="@+id/v_line" ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="1dp" ? ? ? ? android:layout_above="@+id/btn_submit" ? ? ? ? android:background="@android:color/darker_gray"/> ? ? <Button ? ? ? ? android:id="@+id/btn_submit" ? ? ? ? android:layout_width="match_parent" ? ? ? ? android:layout_height="50dp" ? ? ? ? android:layout_alignParentBottom="true" ? ? ? ? android:gravity="center" ? ? ? ? android:text="uodate" ? ? ? ? android:textColor="@android:color/white" ? ? ? ? android:background="@null" ? ? ? ? android:textSize="18sp"/> ? ? </LinearLayout> </RelativeLayout>
在drawable下面創(chuàng)建存放圖片的文件
如何創(chuàng)建,首先復(fù)制圖片.右擊drawable,ctrl +v.
選擇第一個路徑就行.兩個路徑區(qū)別不加以贅述
下面命名就ok.
java代碼
package com.example.a19260234zjh; 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 et_name,et_email,et_pwd; ? ? private Button btn_submit; ? ? private String name,email,pwd,sex,hobbys; ? ? private RadioGroup rg_sex; ? ? private CheckBox cb_sing,cb_dance,cb_read; ? ? @Override ? ? protected void onCreate(Bundle savedInstanceState) { ? ? ? ? super.onCreate(savedInstanceState); ? ? ? ? setContentView(R.layout.activity_main); ? ? ? ? init(); ? ? } ? ? private void init(){ ? ? ? ? et_name=findViewById(R.id.et_name); ? ? ? ? et_email=findViewById(R.id.et_mail); ? ? ? ? et_pwd=findViewById(R.id.et_pwd); ? ? ? ? rg_sex=findViewById(R.id.rg_sex); ? ? ? ? cb_sing=findViewById(R.id.cb_sing); ? ? ? ? cb_read=findViewById(R.id.cb_read); ? ? ? ? cb_dance=findViewById(R.id.cb_dance); ? ? ? ? btn_submit=findViewById(R.id.btn_submit); ? ? ? ? btn_submit.setOnClickListener(this); ? ? ? ? cb_sing.setOnCheckedChangeListener(this); ? ? ? ? cb_dance.setOnCheckedChangeListener(this); ? ? ? ? cb_read.setOnCheckedChangeListener(this); ? ? ? ? hobbys=new String(); ? ? ? ? rg_sex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { ? ? ? ? ? ? @Override ? ? ? ? ? ? public void onCheckedChanged(RadioGroup radioGroup, int checkedId) { ? ? ? ? ? ? ? ? switch (checkedId){ ? ? ? ? ? ? ? ? ? ? case R.id.rb_boy: ? ? ? ? ? ? ? ? ? ? ? ? sex="man"; ? ? ? ? ? ? ? ? ? ? case R.id.rb_girl: ? ? ? ? ? ? ? ? ? ? ? ? sex="woman"; ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? }); ? ? } ? ? private void getData(){ ? ? ? ? name=et_name.getText().toString().trim(); ? ? ? ? email=et_email.getText().toString().trim(); ? ? ? ? pwd=et_pwd.getText().toString().trim(); ? ? } ? ? @Override ? ? public void onClick(View v){ ? ? ? ? switch (v.getId()){ ? ? ? ? ? ? case R.id.btn_submit: ? ? ? ? ? ? ? ? getData(); ? ? ? ? ? ? ? ? if(TextUtils.isEmpty(name)){ ? ? ? ? ? ? ? ? ? ? Toast.makeText(MainActivity.this,"input name", ? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.LENGTH_SHORT).show(); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? else if(TextUtils.isEmpty(email)){ ? ? ? ? ? ? ? ? ? ? Toast.makeText(MainActivity.this,"input email", ? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.LENGTH_SHORT).show(); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? else if(TextUtils.isEmpty(pwd)){ ? ? ? ? ? ? ? ? ? ? Toast.makeText(MainActivity.this,"input password", ? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.LENGTH_SHORT).show(); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ?else if(TextUtils.isEmpty(sex)){ ? ? ? ? ? ? ? ? ? ? Toast.makeText(MainActivity.this,"input glendar", ? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.LENGTH_SHORT).show(); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ?else if(TextUtils.isEmpty(hobbys)){ ? ? ? ? ? ? ? ? ? ? Toast.makeText(MainActivity.this,"input hobbys", ? ? ? ? ? ? ? ? ? ? ? ? ? ? Toast.LENGTH_SHORT).show(); ? ? ? ? ? ? ? ? } else{ ? ? ? ? ? ? ? ? ? ? ?Toast.makeText(MainActivity.this,"success", ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Toast.LENGTH_SHORT).show(); ? ? ? ? ? ? ? ? ? ? Log.i("MainActivity","information"+"name:"+name+",email:"+email+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ",sex"+sex+",hobby"+hobbys); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ?break; ? ? ? ? } ? ? } ? ? @Override ? ? public void onCheckedChanged(CompoundButton buttonViwe,boolean isChecked){ ? ? ? ? String motion=buttonViwe.getText().toString(); ? ? ? ? if(isChecked){ ? ? ? ? ? ? if(!hobbys.contains(motion)){ ? ? ? ? ? ? ? ? hobbys=hobbys+motion; ? ? ? ? ? ? } ? ? ? ? }else { ? ? ? ? ? ? if(hobbys.contains(motion)){ ? ? ? ? ? ? ? ? hobbys=hobbys.replace(motion,""); ? ? ? ? ? ? } ? ? ? ? } ? ? } }
以上就是實現(xiàn)注冊頁面所需要的代碼.
效果如下:
每個人的圖片不一樣,效果也不一樣.建議圖片盡量小一些。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android獲取手機型號/系統(tǒng)版本號/App版本號等信息實例講解
本示例獲得手機型號,系統(tǒng)版本,App版本號等信息,具體實現(xiàn)如下,感興趣的朋友可以參考下哈2013-06-06Android NDK開發(fā)的環(huán)境搭建與簡單示例
本文主要介紹Android NDK的知識,這里整理了相關(guān)資料,來說明如何搭建相應(yīng)環(huán)境和簡單實例,幫助大家理解,有興趣的小伙伴可以參考下2016-09-09Android progressbar實現(xiàn)帶底部指示器和文字的進度條
這篇文章主要為大家詳細介紹了Android progressbar實現(xiàn)帶底部指示器和文字的進度條,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-01-01Android入門之BroadCast模擬實現(xiàn)異地登錄事件發(fā)生后的主動退出
隨著對BroadCast的越來越深入,我們今天要實現(xiàn)一個稍微復(fù)雜一點的BroadCast。即只允許一個設(shè)備登錄一個帳號時,APP會彈一個對話框如:您的賬號在別處登錄,請重新登陸!感興趣的可以了解一下2022-12-12