android 仿微信demo——注冊功能實現(xiàn)(移動端)
移動端注冊功能實現(xiàn)
微信的注冊界面每一個文本段都有下劃線且默認(rèn)顏色都是灰色,當(dāng)其中一個文本段獲取焦點會將下劃線的顏色變?yōu)榫G色,而且文本輸入框的光標(biāo)也是綠色的,還有在文本輸入框沒有全部輸入的情況下,按鈕是不能點擊的,只有當(dāng)文本輸入框全部輸入的情況下才能點擊且此時按鈕會變成綠色。除了這些UI功能外,當(dāng)點擊注冊按鈕是還會把表單數(shù)據(jù)發(fā)送給服務(wù)器
創(chuàng)建activity Reigister.java
activity Reigister.java
package com.example.wxchatdemo; import android.annotation.SuppressLint; import android.content.Intent; import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.annotation.Nullable; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.Toast; import com.example.wxchatdemo.tools.IEditTextChangeListener; import com.example.wxchatdemo.tools.RandomUserName; import com.example.wxchatdemo.tools.WorksSizeCheckUtil; import org.json.JSONObject; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Reigister extends AppCompatActivity { //聲明組件 private EditText username; private EditText phone; private EditText password; private Button button; //隨機微信號 private String randomNumber; //自定義一個UI修改機制 private MyHander myhander = new MyHander(); @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.register); //設(shè)置布局 /* 隱藏自帶標(biāo)題*/ ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.hide(); } if (Build.VERSION.SDK_INT >= 21) { View decorView = getWindow().getDecorView(); int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN //全屏顯示 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; //因為背景為淺色所以將狀態(tài)欄字體設(shè)置為黑色 decorView.setSystemUiVisibility(option); getWindow().setStatusBarColor(Color.TRANSPARENT); } initViews(); // 初始化布局元素 // 設(shè)置注冊按鈕是否可點擊 if (username.getText() + "" == "" || phone.getText() + "" == "" || password.getText() + "" == "") { button.setEnabled(false); } else { button.setEnabled(true); } inputFocus(); //監(jiān)聽EditView變色 buttonChangeColor(); //監(jiān)聽登錄按鈕變色 //button的點擊事件事件 button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /*判斷輸入的手機號格式對不對,對的話開一個線程完成網(wǎng)絡(luò)請求操作*/ Pattern pattern = Pattern .compile("^(13[0-9]|15[0-9]|153|15[6-9]|180|18[23]|18[5-9])\\d{8}$"); Matcher matcher = pattern.matcher(phone.getText()); if (matcher.matches()) { // 開一個線程完成網(wǎng)絡(luò)請求操作 new Thread(new Runnable() { @Override public void run() { httpUrlConnPost(Reigister.this.username.getText() + "", phone.getText() + "", password.getText() + ""); } }).start(); } else { Toast.makeText(getApplicationContext(), "手機格式錯誤", Toast.LENGTH_LONG).show(); } } }); } /*在這里面獲取到每個需要用到的控件的實例*/ @SuppressLint("NewApi") public void initViews() { // 得到所有的組件 username = (EditText) this.findViewById(R.id.reg_name); phone = (EditText) this.findViewById(R.id.reg_phone); password = (EditText) this.findViewById(R.id.reg_passwd); button = (Button) this.findViewById(R.id.reg_button); } /*監(jiān)聽EditView變色*/ public void inputFocus() { username.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { // 此處為得到焦點時的處理內(nèi)容 ImageView imageView = (ImageView) findViewById(R.id.reg_diver1); imageView.setBackgroundResource(R.color.input_dvier_focus); } else { // 此處為失去焦點時的處理內(nèi)容 ImageView imageView = (ImageView) findViewById(R.id.reg_diver1); imageView.setBackgroundResource(R.color.input_dvier); } } }); phone.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { // 此處為得到焦點時的處理內(nèi)容 ImageView imageView = (ImageView) findViewById(R.id.reg_diver2); imageView.setBackgroundResource(R.color.input_dvier_focus); } else { // 此處為失去焦點時的處理內(nèi)容 ImageView imageView = (ImageView) findViewById(R.id.reg_diver2); imageView.setBackgroundResource(R.color.input_dvier); } } }); password.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { // 此處為得到焦點時的處理內(nèi)容 ImageView imageView = (ImageView) findViewById(R.id.reg_diver3); imageView.setBackgroundResource(R.color.input_dvier_focus); } else { // 此處為失去焦點時的處理內(nèi)容 ImageView imageView = (ImageView) findViewById(R.id.reg_diver3); imageView.setBackgroundResource(R.color.input_dvier); } } }); } /*監(jiān)聽登錄按鈕變色*/ public void buttonChangeColor() { //創(chuàng)建工具類對象 把要改變顏色的Button先傳過去 WorksSizeCheckUtil.textChangeListener textChangeListener = new WorksSizeCheckUtil.textChangeListener(button); textChangeListener.addAllEditText(username, phone, password);//把所有要監(jiān)聽的EditText都添加進去 //接口回調(diào) 在這里拿到boolean變量 根據(jù)isHasContent的值決定 Button應(yīng)該設(shè)置什么顏色 WorksSizeCheckUtil.setChangeListener(new IEditTextChangeListener() { @Override public void textChange(boolean isHasContent) { if (isHasContent) { button.setBackgroundResource(R.drawable.login_button_focus); button.setTextColor(getResources().getColor(R.color.loginButtonTextFouse)); } else { button.setBackgroundResource(R.drawable.login_button_shape); button.setTextColor(getResources().getColor(R.color.loginButtonText)); } } }); } /*發(fā)送請求的主要方法*/ public void httpUrlConnPost(String name, String phone, String password) { /*使用工具類生成隨機的微信號*/ RandomUserName ran = new RandomUserName(); randomNumber = ran.generate(); HttpURLConnection urlConnection = null; URL url; try { // 請求的URL地地址 url = new URL( "http://100.2.178.10:8080/AndroidServer_war_exploded/Reigister"); urlConnection = (HttpURLConnection) url.openConnection();// 打開http連接 urlConnection.setConnectTimeout(3000);// 連接的超時時間 urlConnection.setUseCaches(false);// 不使用緩存 // urlConnection.setFollowRedirects(false);是static函數(shù),作用于所有的URLConnection對象。 urlConnection.setInstanceFollowRedirects(true);// 是成員函數(shù),僅作用于當(dāng)前函數(shù),設(shè)置這個連接是否可以被重定向 urlConnection.setReadTimeout(3000);// 響應(yīng)的超時時間 urlConnection.setDoInput(true);// 設(shè)置這個連接是否可以寫入數(shù)據(jù) urlConnection.setDoOutput(true);// 設(shè)置這個連接是否可以輸出數(shù)據(jù) urlConnection.setRequestMethod("POST");// 設(shè)置請求的方式 urlConnection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");// 設(shè)置消息的類型 urlConnection.connect();// 連接,從上述至此的配置必須要在connect之前完成,實際上它只是建立了一個與服務(wù)器的TCP連接 JSONObject json = new JSONObject();// 創(chuàng)建json對象 json.put("number", URLEncoder.encode(randomNumber, "UTF-8"));// 使用URLEncoder.encode對特殊和不可見字符進行編碼 json.put("name", URLEncoder.encode(name, "UTF-8")); json.put("phone", URLEncoder.encode(phone, "UTF-8")); json.put("password", URLEncoder.encode(password, "UTF-8"));// 把數(shù)據(jù)put進json對象中 String jsonstr = json.toString();// 把JSON對象按JSON的編碼格式轉(zhuǎn)換為字符串 // ------------字符流寫入數(shù)據(jù)------------ OutputStream out = urlConnection.getOutputStream();// 輸出流,用來發(fā)送請求,http請求實際上直到這個函數(shù)里面才正式發(fā)送出去 BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));// 創(chuàng)建字符流對象并用高效緩沖流包裝它,便獲得最高的效率,發(fā)送的是字符串推薦用字符流,其它數(shù)據(jù)就用字節(jié)流 bw.write(jsonstr);// 把json字符串寫入緩沖區(qū)中 bw.flush();// 刷新緩沖區(qū),把數(shù)據(jù)發(fā)送出去,這步很重要 out.close(); bw.close();// 使用完關(guān)閉 Log.i("aa", urlConnection.getResponseCode() + ""); //以下判斷是否訪問成功,如果返回的狀態(tài)碼是200則說明訪問成功 if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {// 得到服務(wù)端的返回碼是否連接成功 // ------------字符流讀取服務(wù)端返回的數(shù)據(jù)------------ InputStream in = urlConnection.getInputStream(); BufferedReader br = new BufferedReader( new InputStreamReader(in)); String str = null; StringBuffer buffer = new StringBuffer(); while ((str = br.readLine()) != null) {// BufferedReader特有功能,一次讀取一行數(shù)據(jù) buffer.append(str); } in.close(); br.close(); JSONObject rjson = new JSONObject(buffer.toString()); Log.i("aa", "rjson=" + rjson);// rjson={"json":true} boolean result = rjson.getBoolean("json");// 從rjson對象中得到key值為"json"的數(shù)據(jù),這里服務(wù)端返回的是一個boolean類型的數(shù)據(jù) System.out.println("json:===" + result); //如果服務(wù)器端返回的是true,則說明注冊成功,否則注冊失敗 if (result) {// 判斷結(jié)果是否正確 //在Android中http請求,必須放到線程中去作請求,但是在線程中不可以直接修改UI,只能通過hander機制來完成對UI的操作 myhander.sendEmptyMessage(1); Log.i("用戶:", "注冊成功"); } else { myhander.sendEmptyMessage(2); Log.i("用戶:", "手機號已被注冊"); } } else { myhander.sendEmptyMessage(2); } } catch (Exception e) { e.printStackTrace(); Log.i("aa", e.toString()); myhander.sendEmptyMessage(2); } finally { urlConnection.disconnect();// 使用完關(guān)閉TCP連接,釋放資源 } } // 在Android中不可以在線程中直接修改UI,只能借助Handler機制來完成對UI的操作 class MyHander extends Handler { @Override public void handleMessage(Message msg) { super.handleMessage(msg); //判斷hander的內(nèi)容是什么,如果是1則說明注冊成功,如果是2說明注冊失敗 switch (msg.what) { case 1: Log.i("aa", msg.what + ""); Toast.makeText(getApplicationContext(), "注冊成功", Toast.LENGTH_SHORT).show(); /*跳轉(zhuǎn)到登錄頁面并把微信號也傳過去*/ Intent intent = new Intent(); intent.putExtra("weixin_number", randomNumber); intent.setClass(com.example.wxchatdemo.Reigister.this, LoginUser.class); startActivity(intent); com.example.wxchatdemo.Reigister.this.finish(); //結(jié)束當(dāng)前activity break; case 2: Log.i("aa", msg.what + ""); //這是一個提示消息 Toast.makeText(getApplicationContext(), "手機號已被注冊", Toast.LENGTH_LONG).show(); } } } //返回按鈕處理事件 public void rigister_activity_back(View v) { /*跳轉(zhuǎn)到微信啟動頁*/ Intent intent = new Intent(); intent.setClass(com.example.wxchatdemo.Reigister.this, Welcome.class); startActivity(intent); com.example.wxchatdemo.Reigister.this.finish(); //結(jié)束當(dāng)前activity } }
上面用到的兩個工具類和一個接口,其中一個工具類是監(jiān)聽按鈕變色的,是上面接口的實現(xiàn)類(用到面向接口編程思想,把接口作為自己的成員變量,實現(xiàn)接口回調(diào))另一個工具類是隨機生成微信號,代碼就不全闡述了,注釋都有說明,主要講一下生成微信號的工具類
生成隨機微信號工具類:
注冊微信時系統(tǒng)會給我們隨機生成一個微信號且不能重復(fù)的,所以上面用一個工具類RandomUserName(),通過調(diào)用generate()方法可以返回一個隨機的微信號(封裝的細節(jié)就不說了,等下后面附上工具類代碼都有注釋。這個功能應(yīng)該是在服務(wù)端實現(xiàn)的,我懶,所以簡單在移動端搞了),然后和注冊表單一起發(fā)給服務(wù)器
在創(chuàng)建工具類接口之前,可以先創(chuàng)建一個存放工具類和接口的包,因為后面會繼續(xù)完善微信功能時會創(chuàng)建很多工具類,方便管理
創(chuàng)建存放工具類和接口包
創(chuàng)建監(jiān)聽按鈕變色工具類WorksSizeCheckUtil.java
WorksSizeCheckUtil.java
package com.example.wxchatdemo.tools; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.widget.Button; import android.widget.EditText; public class WorksSizeCheckUtil { static IEditTextChangeListener mChangeListener; public static void setChangeListener(IEditTextChangeListener changeListener) { mChangeListener = changeListener; } //檢測輸入框是否都輸入了內(nèi)容 從而改變按鈕的是否可點擊 public static class textChangeListener { private Button button; private EditText[] editTexts; public textChangeListener(Button button) { this.button = button; } public textChangeListener addAllEditText(EditText... editTexts) { this.editTexts = editTexts; initEditListener(); return this; } private void initEditListener() { //調(diào)用了遍歷editext的方法 for (EditText editText : editTexts) { editText.addTextChangedListener(new textChange()); } } // edit輸入的變化來改變按鈕的是否點擊 private class textChange implements TextWatcher { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { if (checkAllEdit()) { //所有EditText有值了 mChangeListener.textChange(true); button.setEnabled(true); } else { //所有EditText值為空 button.setEnabled(false); mChangeListener.textChange(false); } } @Override public void afterTextChanged(Editable editable) { } } //檢查所有的edit是否輸入了數(shù)據(jù) private boolean checkAllEdit() { for (EditText editText : editTexts) { if (!TextUtils.isEmpty(editText.getText() + "")) { continue; } else { return false; } } return true; } } }
創(chuàng)建對應(yīng)的接口IEditTextChangeListener.java
IEditTextChangeListener.java
package com.example.wxchatdemo.tools; public interface IEditTextChangeListener { void textChange(boolean isHasContent); }
創(chuàng)建隨機生成微信號的工具類RandomUserName.java
RandomUserName.java
package com.example.wxchatdemo.tools; import java.util.Random; public class RandomUserName { private static final char[] eng_char = new char[]{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; private static final String[] first_name = new String[]{"zhao","qian","sun","li","zhou","wang","wu","zheng","feng","chen","chu","wei","jiang","shen","yang" ,"zhu","qin","you","xu","he","shi","zhan","kong","cao","xie","jin","shu","fang","yuan"}; private static final String[] tel_head = new String[]{"13","18","15"}; private static final String[] email_suffix = new String[]{"@gmail.com","@yahoo.com","@msn.com","@hotmail.com","@aol.com","@ask.com" ,"@live.com","@qq.com","@0355.net","@163.com","@163.net","@263.net" ,"@3721.net","@yeah.net","@googlemail.com","@126.com","@sina.com","@sohu.com","@yahoo.com.cn"}; private Random random = new Random(); public String generate(){ StringBuilder uName = new StringBuilder(); int randomType = random.nextInt(Integer.MAX_VALUE)%3; switch (randomType) { case 0: // firstName + randomSecName + birthday uName.append(first_name[random.nextInt(Integer.MAX_VALUE)%first_name.length]) .append(eng_char[random.nextInt(Integer.MAX_VALUE)%eng_char.length]); if(random.nextInt(Integer.MAX_VALUE)%2 == 0){ uName.append(eng_char[random.nextInt(Integer.MAX_VALUE)%eng_char.length]); } // birthday if(random.nextInt(Integer.MAX_VALUE)%2 == 0){ uName.append(String.valueOf(2014 - (random.nextInt(Integer.MAX_VALUE)%(50-15) + 15))); // 大于15小于50歲 } if(random.nextInt(Integer.MAX_VALUE)%2 == 0){ int month = random.nextInt(Integer.MAX_VALUE)%11 + 1; int day = random.nextInt(Integer.MAX_VALUE)%29 + 1; if(month < 10) uName.append("0"); uName.append(month); if(day < 10) uName.append("0"); uName.append(day); } if(random.nextInt(Integer.MAX_VALUE%4) == 0){// add email suffix , 1/4 rate uName.append(email_suffix[random.nextInt(Integer.MAX_VALUE)%email_suffix.length]); } break; case 1: // tel uName.append(tel_head[random.nextInt(Integer.MAX_VALUE)%tel_head.length]) .append(random.nextInt(Integer.MAX_VALUE)%10) .append(random.nextInt(Integer.MAX_VALUE)%10) .append(random.nextInt(Integer.MAX_VALUE)%10) .append(random.nextInt(Integer.MAX_VALUE)%10) .append(random.nextInt(Integer.MAX_VALUE)%10) .append(random.nextInt(Integer.MAX_VALUE)%10) .append(random.nextInt(Integer.MAX_VALUE)%10) .append(random.nextInt(Integer.MAX_VALUE)%10) .append(random.nextInt(Integer.MAX_VALUE)%10); break; case 2: // qq uName.append(random.nextInt(Integer.MAX_VALUE)%9+1) .append(random.nextInt(Integer.MAX_VALUE)%10) .append(random.nextInt(Integer.MAX_VALUE)%10) .append(random.nextInt(Integer.MAX_VALUE)%10) .append(random.nextInt(Integer.MAX_VALUE)%10); int lenth = 0; while(random.nextInt(Integer.MAX_VALUE)%2 == 0){ if(lenth > 6) break; uName.append(random.nextInt(Integer.MAX_VALUE)%10); lenth ++; } break; default: break; } return uName.toString(); } }
創(chuàng)建兩個shapre文件,自定義按鈕形狀,實現(xiàn)按鈕在所有文本框獲取輸入時顯示的背景和至少有一個沒有輸入情況下顯示的背景
按鈕在所以文本框獲取輸入時顯示的shapre文件login_button_focus.xml
login_button_focus.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/loginButtonBackgroundFouse" /><!-- 填充的顏色 --> <!-- 設(shè)置按鈕的四個角為弧形 --> <!-- android:radius 弧形的半徑 --> <corners android:bottomLeftRadius="6dp" android:bottomRightRadius="6dp" android:topLeftRadius="6dp" android:topRightRadius="6dp" /> <!-- 邊框粗細及顏色 --> </shape>
按鈕在所以文本框至少有一個沒有獲取輸入時顯示的shapre文件login_button_shape.xml
login_button_shape.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/loginButtonBackgroundNotFouse" /><!-- 填充的顏色 --> <!-- 設(shè)置按鈕的四個角為弧形 --> <!-- android:radius 弧形的半徑 --> <corners android:bottomLeftRadius="6dp" android:bottomRightRadius="6dp" android:topLeftRadius="6dp" android:topRightRadius="6dp" /> <!-- 邊框粗細及顏色 --> </shape>
創(chuàng)建activity Reigister.java對應(yīng)的布局文件reigister.xml
reigister.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/title" android:orientation="vertical"> <ImageView android:layout_width="17dp" android:layout_height="17dp" android:layout_marginLeft="20dp" android:layout_marginTop="45dp" android:onClick="rigister_activity_back" android:src="@drawable/backpay" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:layout_marginTop="25dp" android:text="手機號注冊" android:textColor="@color/loginText" android:textSize="25sp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="40dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:text="昵稱" android:textColor="@color/loginText" android:textSize="16sp" /> <EditText android:id="@+id/reg_name" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_marginLeft="55dp" android:background="@null" android:hint="例如:陳晨" android:singleLine="true" android:textColorHint="@color/textColorHint" android:textCursorDrawable="@drawable/edit_cursor_color" android:textSize="16sp" /> </LinearLayout> <ImageView android:id="@+id/reg_diver1" android:layout_width="320dp" android:layout_height="1dp" android:layout_gravity="center_horizontal" android:layout_marginTop="17dp" android:background="@color/input_dvier" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:text="手機號" android:textColor="@color/loginText" android:textSize="16sp" /> <EditText android:id="@+id/reg_phone" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_marginLeft="36dp" android:background="@null" android:hint="請?zhí)顚懯謾C號" android:singleLine="true" android:textColorHint="@color/textColorHint" android:textCursorDrawable="@drawable/edit_cursor_color" android:textSize="16sp" /> </LinearLayout> <ImageView android:id="@+id/reg_diver2" android:layout_width="320dp" android:layout_height="1dp" android:layout_gravity="center_horizontal" android:layout_marginTop="17dp" android:background="@color/input_dvier" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:text="密碼" android:textColor="@color/loginText" android:textSize="16sp" /> <EditText android:id="@+id/reg_passwd" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_marginLeft="55dp" android:background="@null" android:hint="請?zhí)顚懨艽a" android:password="false" android:singleLine="true" android:textColorHint="@color/textColorHint" android:textCursorDrawable="@drawable/edit_cursor_color" android:textSize="16sp" /> </LinearLayout> <ImageView android:id="@+id/reg_diver3" android:layout_width="320dp" android:layout_height="1dp" android:layout_gravity="center_horizontal" android:layout_marginTop="17dp" android:background="@color/input_dvier" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="40dp" android:gravity="center_horizontal"> <Button android:id="@+id/reg_button" android:layout_width="321dp" android:layout_height="48dp" android:background="@drawable/login_button_shape" android:text="注冊" android:textColor="@color/loginButtonText" android:textSize="16sp" /> </LinearLayout> </LinearLayout>
創(chuàng)建shape文件edit_cursor_color.xml,自定義光標(biāo)顏色
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <size android:width="1dp" /> <size android:height="10dp"/> <solid android:color="@color/loginButtonBackgroundFouse" /> </shape>
在colors.xml文件中聲明所用到顏色
colors.xml
<color name="input_dvier">#D8D8D8</color> <color name="input_dvier_focus">#1BB879</color> <color name="loginButtonText">#B5B2B2</color> <color name="loginButtonTextFouse">#FFFFFF</color> <color name="loginButtonBackgroundFouse">#07C160</color> <color name="loginButtonBackgroundNotFouse">#D4D8D5</color> <color name="title">#EDEDED</color> <color name="loginText">#5A5959</color> <color name="textColorHint">#DDDDDD</color>
在AndroidMainfest.xml中聲明注冊activity
測試
雖然服務(wù)器代碼還沒實現(xiàn),但是還是可以測試相應(yīng)功能,先把注冊成功后跳轉(zhuǎn)到登錄頁面的那段代碼注釋點
然后再上篇微信啟動頁實現(xiàn)文章中的activity Welcome.java注冊按鈕點擊后跳轉(zhuǎn)的activity代碼注釋取消掉
啟動項目測試
雖然輸入正確的手機號格式,但是服務(wù)器功能還沒實現(xiàn),所以不論怎樣輸入手機號都會出現(xiàn)手機號已被注冊,因為把請求服務(wù)器出現(xiàn)錯誤時執(zhí)行的代碼段寫了手機號已被注冊的提示,這樣做的原因是服務(wù)器出現(xiàn)錯誤就是手機號重復(fù)了。
總結(jié)
這篇關(guān)于微信demo的文章就到這里了,希望大家可以多多關(guān)注腳本之家的更多精彩內(nèi)容!
相關(guān)文章
Android中的webview監(jiān)聽每次URL變化實例
這篇文章主要介紹了Android中的webview監(jiān)聽每次URL變化實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03Android控件ViewFlipper仿淘寶頭條垂直滾動廣告條
這篇文章主要為大家詳細介紹了Android控件ViewFlipper仿淘寶頭條垂直滾動廣告條,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05android使用RxJava實現(xiàn)預(yù)加載
這篇文章主要為大家詳細介紹了android使用RxJava實現(xiàn)預(yù)加載的相關(guān)資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-01-01Android CountDownTimer實現(xiàn)定時器和倒計時效果
這篇文章主要為大家詳細介紹了Android CountDownTimer實現(xiàn)定時器和倒計時效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-02-02在Ubuntu下搭建Android開發(fā)環(huán)境
對一個程序猿來說,裝好系統(tǒng)之后的第一件事,一定是搭建開發(fā)環(huán)境,已經(jīng)安裝各種開發(fā)工具,以便之后能方便順利地進行程序的開發(fā)。簡單的介紹下在Ubuntu環(huán)境下搭建Android開發(fā)環(huán)境,雖然基本上和在Windows下沒有太大差別,但有些細節(jié)上還是很值得注意的。2014-07-07