Quantcast
Channel: Android*
Viewing all articles
Browse latest Browse all 531

Android 开发之登录 &注册 UI

$
0
0

 

第一步:自定义属性(/res/values/attrs.xml)

 

[html] view plaincop
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <declare-styleable name="delete_edittext">  
  4.         <attr name="height" format="reference|dimension" />  
  5.         <attr name="paddingleft" format="reference|dimension" />  
  6.         <attr name="hint" format="reference|string" />  
  7.         <attr name="hint_size" format="reference|dimension" />  
  8.         <attr name="hint_color" format="reference|color" />  
  9.         <attr name="delete_edittype" format="string" />  
  10.     </declare-styleable>  
  11. </resources>  

 

 

第二步:自定义View(LoginEditText.java)

 

[java] view plaincop
 
  1. public class LoginEditText extends RelativeLayout {  
  2.     //取消按钮  
  3.     private ImageView cancelIm;  
  4.     private EditText searchEt;  
  5.     //ed的高度  
  6.     private float edHieght;  
  7.     //距离左边的距离  
  8.     private float edPaddingleft;  
  9.     //提示文字  
  10.     private String hint;  
  11.     private float hintSize;  
  12.     private int hintColor;  
  13.     //ed的类型  
  14.     private String edittype;  
  15.   
  16.     public LoginEditText(Context context) {  
  17.         super(context);  
  18.     }  
  19.   
  20.     public LoginEditText(Context context, AttributeSet attrs) {  
  21.         super(context, attrs);  
  22.         initView(context,attrs);  
  23.     }  
  24.   
  25.     public EditText getSearchEt() {  
  26.         return searchEt;  
  27.     }  
  28.   
  29.     private void initView(Context context,AttributeSet attrs) {  
  30.         LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
  31.         inflater.inflate(R.layout.login_edittext, this); //<span style="color:#ff0000;">这是引用了布局文件</span>  
  32.         cancelIm=(ImageView) findViewById(R.id.cancel_im);  
  33.         searchEt = (EditText) findViewById(R.id.search_et);  
  34.         TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.delete_edittext);//得到属性数组  
  35.         edHieght  = a.getDimension(R.styleable.delete_edittext_height, 60f);//得到高度属性值,  
  36.         edPaddingleft  = a.getDimension(R.styleable.delete_edittext_paddingleft, 10f);//得到padding属性值,  
  37.         hint  = a.getString(R.styleable.delete_edittext_hint);//得到hint属性值,  
  38.         hintSize  = a.getDimension(R.styleable.delete_edittext_hint_size,19f);//得到hintsize属性值,  
  39.         hintColor  = a.getColor(R.styleable.delete_edittext_hint_color,context.getResources().getColor(R.color.c_c));//得到hintcolor属性值,  
  40.   
  41.         edittype  = a.getString(R.styleable.delete_edittext_delete_edittype);  
  42.         if("pwd".equals(edittype)) {  
  43.             searchEt.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);  
  44.         }  
  45.   
  46.         searchEt.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,(int)edHieght));  
  47.         searchEt.setPadding((int)edPaddingleft, 000);  
  48.         searchEt.setHint(hint);  
  49.         searchEt.setHintTextColor(hintColor);  
  50.         searchEt.addTextChangedListener(new TextWatcher() {  
  51.             @Override  
  52.             public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {  
  53.             }  
  54.   
  55.             @Override  
  56.             public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {  
  57.                 if(TextUtils.isEmpty(charSequence)) {  
  58.                     cancelIm.setVisibility(GONE);  
  59.                 } else {  
  60.                     cancelIm.setVisibility(VISIBLE);  
  61.                 }  
  62.             }  
  63.   
  64.             @Override  
  65.             public void afterTextChanged(Editable editable) {  
  66.             }  
  67.         });  
  68.   
  69.         cancelIm.setOnClickListener(new OnClickListener() {  
  70.             @Override  
  71.             public void onClick(View view) {  
  72.                 searchEt.setText("");  
  73.             }  
  74.         });  
  75.     }  
  76.   
  77.     public LoginEditText(Context context, AttributeSet attrs, int defStyle) {  
  78.         super(context, attrs, defStyle);  
  79.         initView(context,attrs);  
  80.     }  
  81. }  


第三步:布局文件(/res/layout/login_edittext.xml)

[html] view plaincopy
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="wrap_content"  
  5.     android:layout_below="@+id/head">  
  6.   
  7.     <EditText  
  8.         android:id="@+id/search_et"  
  9.         android:layout_width="fill_parent"  
  10.         android:layout_height="@dimen/s_59dp"  
  11.         android:layout_centerVertical="true"  
  12.         android:layout_marginLeft="@dimen/s_10dp"  
  13.         android:layout_marginRight="@dimen/s_10dp"  
  14.         android:layout_marginTop="@dimen/s_9dp"  
  15.         android:background="@drawable/category_search_shape" //<span style="color:#ff0000;">这里引用了shape</span>  
  16.         android:paddingLeft="@dimen/s_40dp"  
  17.         android:paddingRight="@dimen/s_40dp"  
  18.         android:singleLine="true"  
  19.         android:textColor="@color/login_ed_hintcolor"  
  20.         android:textSize="@dimen/s_17dp" />  
  21.   
  22.     <RelativeLayout  
  23.         android:id="@+id/cancel_click"  
  24.         android:layout_width="@dimen/s_35dp"  
  25.         android:layout_height="@dimen/s_36dp"  
  26.         android:layout_alignRight="@+id/search_et"  
  27.         android:layout_centerVertical="true">  
  28.   
  29.         <ImageView  
  30.             android:id="@+id/cancel_im"  
  31.             android:layout_width="wrap_content"  
  32.             android:layout_height="wrap_content"  
  33.             android:layout_alignParentRight="true"  
  34.             android:layout_centerVertical="true"  
  35.             android:layout_marginRight="@dimen/s_6dp"  
  36.             android:src="@drawable/qx"  
  37.             android:visibility="gone" />  
  38.     </RelativeLayout>  
  39. </RelativeLayout>  

 

 

第四步:shape文件(/res/drawable/category_search_shape.xml)

[html] view plaincopy
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2.   
  3. <shape xmlns:android="http://schemas.android.com/apk/res/android">  
  4.     <solid android:color="#00000000" />  
  5. </shape>  


第五步:整体布局(activity_main.xml)

 

[java] view plaincopy
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.               xmlns:offcn="http://schemas.android.com/apk/res-auto" //<span style="color:#ff0000;">引用自定义属性</span>  
  4.               android:background="@drawable/dt"  
  5.               android:orientation="vertical"  
  6.               android:layout_width="fill_parent"  
  7.               android:layout_height="fill_parent"  
  8.         >  
  9.     <LinearLayout  
  10.             android:id="@+id/user_input"  
  11.             android:layout_width="fill_parent"  
  12.             android:layout_height="@dimen/s_120dp"  
  13.             android:background="@drawable/login_shape" //<span style="color:#ff0000;">引用了shape</span>  
  14.             android:layout_marginLeft="@dimen/s_15dp"  
  15.             android:layout_marginRight="@dimen/s_15dp"  
  16.             android:layout_marginTop="@dimen/s_192dp"  
  17.             android:orientation="vertical"  
  18.             >  
  19.         <RelativeLayout  
  20.                 android:layout_width="fill_parent"  
  21.                 android:layout_height="wrap_content">  
  22.             <cn.zanelove.smscaptcha.DeleteEditText  //<span style="color:#ff0000;">引用自定义View</span>  
  23.                     android:id="@+id/username_ed"  
  24.                     android:layout_width="fill_parent"  
  25.                     android:layout_height="@dimen/s_59dp"  
  26.                     offcn:height="@dimen/s_59dp"  
  27.                     offcn:hint="请输入您的用户名"  
  28.                     offcn:hint_color="#2cc597"  
  29.                     offcn:paddingleft="@dimen/s_60dp"  
  30.                     />  
  31.             <ImageView  
  32.                     android:layout_width="wrap_content"  
  33.                     android:layout_height="wrap_content"  
  34.                     android:src="@drawable/yh"  
  35.                     android:layout_centerVertical="true"  
  36.                     android:layout_marginLeft="@dimen/s_20dp"  
  37.                     />  
  38.         </RelativeLayout>  
  39.         <View android:layout_width="fill_parent"  
  40.               android:layout_height="@dimen/s_1dp"  
  41.               android:background="#10a679"  
  42.                 />  
  43.         <RelativeLayout  
  44.                 android:layout_width="fill_parent"  
  45.                 android:layout_height="wrap_content">  
  46.             <cn.zanelove.smscaptcha.DeleteEditText  
  47.                     android:id="@+id/pwd_ed"  
  48.                     android:layout_width="fill_parent"  
  49.                     android:layout_height="@dimen/s_59dp"  
  50.                     offcn:height="@dimen/s_59dp"  
  51.                     offcn:hint="请输入密码"  
  52.                     offcn:hint_color="#2cc597"  
  53.                     offcn:paddingleft="@dimen/s_60dp"  
  54.                     />  
  55.             <ImageView  
  56.                     android:layout_width="wrap_content"  
  57.                     android:layout_height="wrap_content"  
  58.                     android:src="@drawable/mm"  
  59.                     android:layout_centerVertical="true"  
  60.                     android:layout_marginLeft="@dimen/s_20dp"  
  61.                     />  
  62.         </RelativeLayout>  
  63.     </LinearLayout>  
  64. </LinearLayout>  


第六步:

 

 

[html] view plaincopy
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <solid android:color="@color/login_shape"/>  
  4.     <corners android:radius="@dimen/s_5dp"/>  
  5. </shape>  

 

 

在布局文件中:

 

[java] view plaincopy
 
  1. <TextView  
  2.             android:id="@+id/login"  
  3.             style="@style/login_btn"  
  4.             android:text="@string/login"  
  5.             />  


在上面的代码中不难发现,我们使用了style引用,因此在style_layout.xml中:

 

 

[java] view plaincopy
 
  1. <!-- 登录注册等按钮-->  
  2. <style name="login_btn">  
  3.         <item name="android:layout_width">fill_parent</item>  
  4.         <item name="android:layout_height">@dimen/s_55dp</item>  
  5.         <item name="android:textColor">@color/f</item>  
  6.         <item name="android:textSize">@dimen/s_21dp</item>  
  7.         <item name="android:layout_marginLeft">@dimen/s_15dp</item>  
  8.         <item name="android:layout_marginRight">@dimen/s_15dp</item>  
  9.         <item name="android:background">@drawable/loginbtn_selector</item>  
  10.         <item name="android:gravity">center</item>  
  11. </style>  

 

仔细看的话,我们还引用了background,因此在/res/drawable/下,创建loginbtn_selector.xml文件:

在loginbtn_selector.xml中:

 

[java] view plaincopy
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <item android:state_pressed="true" android:drawable="@drawable/login_loginbtn_press_shape" />  
  4.     <item android:drawable="@drawable/login_loginbtn_shape"/>  
  5. </selector>  


在login_loginbtn_press_shape.xml中:

 

 

[java] view plaincopy
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <corners android:radius="@dimen/s_3dp"/>  
  4.     <solid android:color="@color/login_loginbtn_press"/> //502fc89a  
  5. </shape>  


在login_loginbtn_shape.xml中:

 

 

[java] view plaincopy
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <corners android:radius="@dimen/s_3dp"/>  
  4.     <solid android:color="@color/login_loginbtn"/> //#902fc89a  
  5. </shape>  

 

 

注册UI:

在布局文件中:

 

[html] view plaincopy
 
  1. <LinearLayout  
  2.             android:id="@+id/user_regedit_input"  
  3.             android:layout_width="fill_parent"  
  4.             android:layout_height="@dimen/s_181dp"  
  5.             android:orientation="vertical"  
  6.             android:layout_marginLeft="@dimen/s_15dp"  
  7.             android:layout_marginRight="@dimen/s_15dp"  
  8.             android:background="@drawable/login_shape"  
  9.             android:layout_marginTop="@dimen/s_112dp"  
  10.             >  
  11.             <com.offcn.android.wangxiao.view.RegeditEdittext  
  12.                 android:id="@+id/username_ed"  
  13.                 android:layout_width="fill_parent"  
  14.                 android:layout_height="@dimen/s_60dp"  
  15.                 offcn:text="@string/regedit_username_text"  
  16.                 offcn:hint_rg="@string/regedit_username_hint"  
  17.                 offcn:hint_color_rg="@color/color_999" //#999999  
  18.             <span style="white-space:pre">    </span>/>  
  19.             <View android:layout_width="fill_parent"  
  20.                   android:layout_height="@dimen/s_1dp"  
  21.                   android:background="@color/login_ed_division"  
  22.                   />  
  23.             <com.offcn.android.wangxiao.view.RegeditEdittext  
  24.                     android:id="@+id/pwd_ed"  
  25.                     android:layout_width="fill_parent"  
  26.                     android:layout_height="@dimen/s_60dp"  
  27.                     offcn:text="@string/regedit_pwd_text"  
  28.                     offcn:edittype="pwd"  
  29.                     offcn:hint_rg="@string/regedit_pwd_hint"  
  30.                     offcn:hint_color_rg="@color/regedit_hint" //#bbbbbb  
  31.                     />  
  32.             <View android:layout_width="fill_parent"  
  33.                   android:layout_height="@dimen/s_1dp"  
  34.                   android:background="@color/login_ed_division"  
  35.                   />  
  36.             <com.offcn.android.wangxiao.view.RegeditEdittext  
  37.                     android:id="@+id/repwd_ed"  
  38.                     android:layout_width="fill_parent"  
  39.                     android:layout_height="@dimen/s_60dp"  
  40.                     offcn:text="@string/regedit_repwd_text"  
  41.                     offcn:edittype="pwd"  
  42.                     offcn:hint_rg="@string/regedit_pwd_hint"  
  43.                     offcn:hint_color_rg="@color/regedit_hint"  
  44.                     />  
  45.             <View android:layout_width="fill_parent"  
  46.                   android:layout_height="@dimen/s_1dp"  
  47.                   android:background="@color/login_ed_division" //#10a679  
  48.                   />  
  49. </LinearLayout>  

 

 

此处使用了自定义EditText(RegeditEdittext):

 

[java] view plaincopy
 
  1. /** 
  2.  * 注册页面edittext 
  3.  * edittype传入email检测email,传入其他则是检验长度是否满足6-10位 
  4.  */  
  5. public class RegeditEdittext extends RelativeLayout {  
  6.   
  7.     //输入内容是否合法的状态图片  
  8.     private ImageView checkIm;  
  9.     private EditText edit;  
  10.     private String edittype;  
  11.     private String inputtype;  
  12.     //是否通过校验  
  13.     private boolean isCheck;  
  14.     //控件左边的文字  
  15.     private String text;  
  16.     private TextView tv;  
  17.     //提示文字  
  18.     private String hint;  
  19.     private float hintSize;  
  20.     private int hintColor;  
  21.   
  22.     public RegeditEdittext(Context context, AttributeSet attrs, int defStyle) {  
  23.         super(context, attrs, defStyle);  
  24.         initView(context, attrs);  
  25.     }  
  26.   
  27.     public RegeditEdittext(Context context) {  
  28.         super(context);  
  29.     }  
  30.   
  31.     public RegeditEdittext(Context context, AttributeSet attrs) {  
  32.         super(context, attrs);  
  33.         initView(context, attrs);  
  34.     }  
  35.   
  36.     public ImageView getCheckIm() {  
  37.         return checkIm;  
  38.     }  
  39.   
  40.     public EditText getEdit() {  
  41.         return edit;  
  42.     }  
  43.   
  44.     public boolean isCheck() {  
  45.         return isCheck;  
  46.     }  
  47.   
  48.     private void initView(Context context, AttributeSet attrs) {  
  49.         LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
  50.         inflater.inflate(R.layout.regedit_edittext, this);  
  51.         edit = (EditText) findViewById(R.id.regedit_et);  
  52.         checkIm = (ImageView) findViewById(R.id.checkIm);  
  53.         tv = (TextView) findViewById(R.id.tv);  
  54.         TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.regedit_edittext);//得到属性数组  
  55.         edittype = a.getString(R.styleable.regedit_edittext_edittype);//得到属性值,可以指定默认值  
  56.         inputtype = a.getString(R.styleable.regedit_edittext_inputtype);  
  57.         hint  = a.getString(R.styleable.regedit_edittext_hint_rg);//得到hint属性值,  
  58.         hintSize  = a.getDimension(R.styleable.regedit_edittext_hint_size_rg,19f);//得到hintsize属性值,  
  59.         hintColor  = a.getColor(R.styleable.regedit_edittext_hint_color_rg,context.getResources().getColor(R.color.c_c));//得到hintcolor属性值,  
  60.         text = a.getString(R.styleable.regedit_edittext_text);  
  61.         edit.setHint(hint);  
  62.         edit.setHintTextColor(hintColor);  
  63.         tv.setText(text);  
  64.         if ("pwd".equals(edittype)) {  
  65.             edit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);  
  66.         }  
  67.         //1代表数字 2代表文字  
  68.         if ("1".equals(inputtype)) {  
  69.             edit.setInputType(InputType.TYPE_CLASS_NUMBER);  
  70.         } else if ("2".equals(inputtype)) {  
  71.             edit.setInputType(InputType.TYPE_CLASS_TEXT);  
  72.         }  
  73.         edit.setLongClickable(false);  
  74.         edit.addTextChangedListener(new TextWatcher() {  
  75.             @Override  
  76.             public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {  
  77.             }  
  78.   
  79.             @Override  
  80.             public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {  
  81.                 if (!TextUtils.isEmpty(charSequence)) {  
  82.                     checkIm.setVisibility(VISIBLE);  
  83.                     //如果是邮箱类型的et,则正则检测邮箱  
  84.                     if ("email".equals(edittype)) {  
  85.                         if (checkEmail(charSequence.toString())) {  
  86.                             checkIm.setImageResource(R.drawable.zq);  
  87.                             isCheck = true;  
  88.                         } else {  
  89.                             checkIm.setImageResource(R.drawable.cw);  
  90.                             isCheck = false;  
  91.                         }  
  92.                         //如果是其他类型,则正则检测长度  
  93.                     } else if ("nocheck".equals(edittype)) {  
  94.                         checkIm.setVisibility(GONE);  
  95.                     } else {  
  96.                         if (checkEditLength(charSequence.toString())) {  
  97.                             checkIm.setImageResource(R.drawable.zq);  
  98.                             isCheck = true;  
  99.                         } else {  
  100.                             checkIm.setImageResource(R.drawable.cw);  
  101.                             isCheck = false;  
  102.                         }  
  103.                     }  
  104.                 }  
  105.             }  
  106.   
  107.             @Override  
  108.             public void afterTextChanged(Editable editable) {  
  109.             }  
  110.         });  
  111.     }  
  112.   
  113.     /** 
  114.      * 验证邮箱地址是否正确 
  115.      */  
  116.     public boolean checkEmail(String email) {  
  117.         boolean flag = false;  
  118.         String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";  
  119.         Pattern regex = Pattern.compile(check);  
  120.         Matcher matcher = regex.matcher(email);  
  121.         flag = matcher.matches();  
  122.         return flag;  
  123.     }  
  124.   
  125.     public boolean checkEditLength(String str) {  
  126.         boolean flag = false;  
  127.         String check = "([0-9]|[A-Za-z]|[\u4e00-\u9fa5]){6,10}";  
  128.         Pattern regex = Pattern.compile(check);  
  129.         Matcher matcher = regex.matcher(str);  
  130.         flag = matcher.matches();  
  131.         return flag;  
  132.     }  
  133. }  

 

注册逻辑代码:

 

[java] view plaincopy
 
  1. /** 
  2.  * 注册 
  3.  */  
  4. public class RegeditActivity extends BaseActivity {  
  5.     //账号  
  6.     @ViewInject(R.id.username_ed)  
  7.     private RegeditEdittext username;  
  8.     //输入密码ed  
  9.     @ViewInject(R.id.pwd_ed)  
  10.     private RegeditEdittext pwd;  
  11.     //确认密码ed  
  12.     @ViewInject(R.id.repwd_ed)  
  13.     private RegeditEdittext rePwd;  
  14.     //注册  
  15.     @ViewInject(R.id.regedit)  
  16.     private TextView regedit;  
  17.   
  18.     private String emailStr;  
  19.     private String pwdStr;  
  20.     private String rePwdStr;  
  21.     private Toast toast;  
  22.   
  23.     private InputMethodManager inputMethodManager;  
  24.     @Override  
  25.     public void onCreate(Bundle savedInstanceState) {  
  26.         super.onCreate(savedInstanceState);  
  27.         setContentView(R.layout.activity_regedit);  
  28.         AppManager.getAppManager().addActivity(this);  
  29.         ViewUtils.inject(this);  
  30.         toast = Toast.makeText(this"", Toast.LENGTH_SHORT);  
  31.         checkRePwd();  
  32.         inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
  33.     }  
  34.   
  35.     /** 
  36.      * 检查密码是否与第一次一致 
  37.      */  
  38.     private void checkRePwd() {  
  39.         rePwd.getEdit().addTextChangedListener(new TextWatcher() {  
  40.             @Override  
  41.             public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {  
  42.   
  43.             }  
  44.   
  45.             @Override  
  46.             public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {  
  47.                 if (!TextUtils.isEmpty(charSequence) && pwd.getEdit().getText() != null) {  
  48.                     if (charSequence.toString().equals((pwd.getEdit().getText().toString()))) {  
  49.                         rePwd.getCheckIm().setImageResource(R.drawable.zq);  
  50.                     } else {  
  51.                         rePwd.getCheckIm().setImageResource(R.drawable.cw);  
  52.                     }  
  53.                 }  
  54.             }  
  55.   
  56.             @Override  
  57.             public void afterTextChanged(Editable editable) {  
  58.   
  59.             }  
  60.         });  
  61.     }  
  62.   
  63.     /** 
  64.      * 注册 
  65.      * @param v 
  66.      */  
  67.     @OnClick(R.id.regedit)  
  68.     public void regedit(View v) {  
  69.         emailStr = username.getEdit().getText().toString().trim();  
  70.         pwdStr = pwd.getEdit().getText().toString().trim();  
  71.         rePwdStr = rePwd.getEdit().getText().toString().trim();  
  72.         if (TextUtils.isEmpty(emailStr)) {  
  73.             toast.setText("邮箱不能为空");  
  74.             toast.show();  
  75.             return;  
  76.         }  
  77.         if (!username.isCheck()) {  
  78.             toast.setText("邮箱格式不正确,请重新输入");  
  79.             toast.show();  
  80.             return;  
  81.         }  
  82.         if (TextUtils.isEmpty(pwdStr)) {  
  83.             toast.setText("密码不能为空,请重新输入");  
  84.             toast.show();  
  85.             return;  
  86.         }  
  87.         if (!pwd.isCheck()) {  
  88.             toast.setText("密码格式不正确,请重新输入");  
  89.             toast.show();  
  90.             return;  
  91.         }  
  92.         if (!pwdStr.equals(rePwdStr)) {  
  93.             toast.setText("两次密码输入不一致,请重新输入");  
  94.             toast.show();  
  95.             return;  
  96.         }  
  97.   
  98.         regedit.setClickable(false);  
  99.         regeditSuccess(username.getEdit().getText().toString(),pwd.getEdit().getText().toString());  
  100.     }  
  101.   
  102.     /** 
  103.      * 去登录 
  104.      * @param v 
  105.      */  
  106.     @OnClick(R.id.tologin)  
  107.     public void toLogin(View v) {  
  108.         Intent intent = new Intent();  
  109.         intent.setClass(this,LoginActivity.class);  
  110.         startActivity(intent);  
  111.         finish();  
  112.     }  
  113.   
  114.     /** 
  115.      * 注册成功 
  116.      */  
  117.     private void regeditSuccess(final String email, final String password) {  
  118.         mDialog.showDialog();  
  119.         inputMethodManager.hideSoftInputFromWindow(rePwd.getEdit().getWindowToken(), 0);  
  120.         HttpUtils httpUtils = new HttpUtils();  
  121.         httpUtils.send(HttpRequest.HttpMethod.GET, OnlineSchoolUtil.getRegUrl(email, password), new RequestCallBack<String>() {  
  122.             @Override  
  123.             public void onSuccess(ResponseInfo<String> responseInfo) {  
  124.                 prepare(responseInfo.result,email,password);  
  125.             }  
  126.   
  127.             @Override  
  128.             public void onFailure(HttpException e, String s) {  
  129.                 mDialog.cancelDialog();  
  130.                 toast.setText("注册失败");  
  131.                 toast.show();  
  132.             }  
  133.         });  
  134.     }  
  135.   
  136.     private void prepare(String result,String email,String password) {  
  137.         FlagBean entity = GsonUtil.json2Bean(this, result, FlagBean.class);  
  138.         if(entity != null && entity.getFlag().equals("3")) {  
  139.             mDialog.cancelDialog();  
  140.             Intent intent = new Intent();  
  141.             intent.setClass(this, RegeditSuccessActivity.class);  
  142.             intent.putExtra("username", email);  
  143.             intent.putExtra("pwd", password);  
  144.             startActivity(intent);  
  145.             finish();  
  146.         }else {  
  147.             mDialog.cancelDialog();  
  148.             toast.setText("注册失败");  
  149.             toast.show();  
  150.         }  
  151.     }  
  152.   
  153.     private void regedutfaild(){  
  154.         toast.setText("登录失败");  
  155.         toast.show();  
  156.     }  
  157. }  

 

在regedit_edittext.xml中:

 

[html] view plaincopy
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.                 android:layout_width="fill_parent"  
  4.                 android:layout_height="wrap_content">  
  5.     <TextView android:id="@+id/tv"  
  6.               android:layout_width="@dimen/s_85dp"  
  7.               android:layout_height="wrap_content"  
  8.               android:text="asfg"  
  9.               android:layout_centerVertical="true"  
  10.               android:gravity="end"  
  11.               android:textColor="@color/color_333"  
  12.               android:textSize="@dimen/s_18dp"  
  13.             />  
  14.     <EditText  
  15.             android:id="@+id/regedit_et"  
  16.             android:layout_width="fill_parent"  
  17.             android:layout_height="@dimen/s_60dp"  
  18.             android:background="#00000000"  
  19.             android:paddingLeft="@dimen/s_106dp"  
  20.             android:paddingRight="@dimen/s_40dp"  
  21.             android:singleLine="true"  
  22.             android:textSize="@dimen/s_14dp"  
  23.             />  
  24.   
  25.     <ImageView  
  26.             android:id="@+id/checkIm"  
  27.             android:layout_width="wrap_content"  
  28.             android:layout_height="wrap_content"  
  29.             android:layout_alignRight="@+id/regedit_et"  
  30.             android:layout_centerVertical="true"  
  31.             android:layout_marginRight="@dimen/s_10dp"  
  32.             android:src="@drawable/cw"  
  33.             android:visibility="gone"/>  
  34.   
  35. </RelativeLayout>  


属性数组(regedit_eidttext):

 

 

[html] view plaincopy
 
  1. <declare-styleable name="regedit_edittext">  
  2.         <attr name="edittype" format="string" />  
  3.         <attr name="inputtype" format="reference|enum">  
  4.             <enum name="string" value="0"/>  
  5.             <enum name="num" value="1"/>  
  6.         </attr>  
  7.         <attr name="text" format="string"/>  
  8.         <attr name="hint_rg" format="reference|string" />  
  9.         <attr name="hint_size_rg" format="reference|dimension" />  
  10.         <attr name="hint_color_rg" format="reference|color" />  
  11. </declare-styleable>  

Icon Image: 

  • Android*
  • Developers
  • Professors
  • Students
  • Android*
  • Theme Zone: 

    Android

    Include in RSS: 

    1

    Viewing all articles
    Browse latest Browse all 531


    <script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>