android一个注册页面和验证码的实现

先上效果图:



验证码采用PHP返回的imageview来实现,xml如下:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent" 
	android:layout_height="fill_parent"
	android:background="#f3f3f9">
	<LinearLayout
		android:orientation="vertical"
		android:layout_width="fill_parent" 
		android:layout_height="fill_parent">
		<RelativeLayout
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:layout_margin="10dp">
			<TextView
				android:id="@+id/tvUsrname"
				android:text="用户名"
				android:layout_width="wrap_content"
				android:layout_height="48dp"
				android:gravity="center_vertical"
				android:textColor="@android:color/black"/>
			<EditText
				android:id="@+id/etUsrname"
				android:layout_width="fill_parent"
				android:layout_height="48dp"
				android:layout_marginLeft="5dp"
				android:textSize="16sp"
				android:layout_toRightOf="@id/tvUsrname"
				android:textColor="@android:color/black"
				android:selectAllOnFocus="true" />
		</RelativeLayout>
		<RelativeLayout
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:layout_margin="10dp">
			<TextView
				android:id="@+id/tvPassword"
				android:text="密码"
				android:layout_width="wrap_content"
				android:layout_height="48dp"
				android:gravity="center_vertical"
				android:textColor="@android:color/black"/>
			<EditText
				android:id="@+id/etPassword"
				android:layout_width="fill_parent"
				android:layout_height="48dp"
				android:layout_marginLeft="5dp"
				android:layout_toRightOf="@id/tvPassword"
				android:textSize="16sp"
				android:password="true"
				android:textColor="@android:color/black" />
		</RelativeLayout>
		<RelativeLayout
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:layout_margin="10dp">
			<TextView
				android:id="@+id/tvPasswordConfirm"
				android:text="密码确认"
				android:layout_width="wrap_content"
				android:layout_height="48dp"
				android:gravity="center_vertical"
				android:textColor="@android:color/black"/>
			<EditText
				android:id="@+id/etPasswordConfirm"
				android:layout_width="fill_parent"
				android:layout_height="48dp"
				android:textSize="16sp"
				android:layout_toRightOf="@id/tvPasswordConfirm"
				android:password="true"
				android:textColor="@android:color/black" />
		</RelativeLayout>
		
		<RelativeLayout
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:layout_margin="10dp">
			<TextView
				android:id="@+id/tvNickName"
				android:text="nickname"
				android:layout_width="wrap_content"
				android:layout_height="48dp"
				android:gravity="center_vertical"
				android:textColor="@android:color/black"/>
			<EditText
				android:id="@+id/etNickName"
				android:layout_width="fill_parent"
				android:layout_height="48dp"
				android:layout_marginLeft="5dp"
				android:maxLines="2"
				android:textSize="16sp"
				android:layout_toRightOf="@id/tvNickName"
				android:textColor="@android:color/black" />
		</RelativeLayout>
		<RelativeLayout
			android:layout_width="fill_parent"
			android:layout_height="wrap_content"
			android:layout_margin="10dp">
			
		<TextView 
			android:id="@+id/tvGender"
			android:text="sex"
	        android:textColor="#484848"
	        android:layout_centerVertical="true"
	        android:textSize="16dp"
	        android:layout_width="wrap_content"
	        android:layout_height="wrap_content"/>
    	<RadioGroup
	        android:id="@+id/rgSex"
	        android:layout_width="fill_parent"
	        android:layout_height="wrap_content"
	        android:layout_marginLeft="5dip"
	        android:layout_toRightOf="@id/tvGender"
	        android:layout_marginBottom="10dp"
	        android:orientation="horizontal" >
	        <RadioButton
	            android:id="@+id/rbrgMale"
	            android:layout_width="wrap_content"
	            android:layout_height="wrap_content"
	            android:textColor="@android:color/black"
	            android:text="male" />
	        <RadioButton
	            android:id="@+id/rbrgFemale"
	            android:layout_width="wrap_content"
	            android:layout_height="wrap_content"
	            android:textColor="@android:color/black"
	            android:text="female"
	            android:layout_marginLeft="50dp" />
    </RadioGroup>
    </RelativeLayout>
    
    <RelativeLayout
    	android:layout_width="fill_parent"
    	android:layout_height="wrap_content">
	    <ImageView
	    	android:id="@+id/ivAuthPic"
	    	android:src="@drawable/image1"          
	    	android:layout_marginLeft="40dp"
	    	android:layout_alignParentLeft="true"
	    	android:layout_centerVertical="true"
	    	android:layout_width="100dp"
	    	android:layout_height="30dp"/>
	    <Button
	    	android:id="@+id/btnChangeaAuthPic"
	    	android:layout_width="wrap_content"
	    	android:layout_height="wrap_content"
	    	android:layout_alignParentRight="true"	
	    	android:layout_gravity="right"
	    	android:layout_marginRight="10dp"
	    	android:text="看不清"
	    	android:textColor="#000"/>
    </RelativeLayout>
    
    <EditText
		android:id="@+id/etAuthCode"
		android:layout_width="fill_parent"
		android:layout_height="48dp"
		android:layout_margin="10dp"
		android:inputType="textVisiblePassword"
		android:textColor="@android:color/black"/>
		
		
    <Button
    	android:id="@+id/btnOk"
    	android:textSize="15sp"
    	android:textColor="#fff"
   		android:text="确认"
   		android:background="@drawable/button_item_selector"
   		android:layout_gravity="center"
   		android:layout_height="wrap_content"
   		android:layout_width="wrap_content"/>
	</LinearLayout>
</ScrollView>

代码:

	int[] array = new int[]{R.drawable.image1,R.drawable.image2,R.drawable.image3};
	boolean isMale;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.registerquick);
		
		RadioButton rbMale = (RadioButton) findViewById(R.id.rbrgMale);
		RadioButton rbfMale = (RadioButton) findViewById(R.id.rbrgFemale);
		rbMale.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				isMale = true;
			}

		});
		rbfMale.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				isMale = false;
			}

		});
		final ImageView ivAuthPic = (ImageView)findViewById(R.id.ivAuthPic);
		Button btnChangeaAuthPic = (Button)findViewById(R.id.btnChangeaAuthPic);
		btnChangeaAuthPic.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Random d = new Random();
				int k = Math.abs(d.nextInt()) % 3;
				ivAuthPic.setImageResource(array[k]);
				
				
			}
		});
	}



  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现手机号登录注册功能,需要使用到短信验证服务。以下是一个简单的实现步骤: 1. 集成短信验证服务。可以使用第三方服务商提供的 SDK 或者自己开发后端接口。 2. 创建注册页面登录页面的布局。 3. 在注册页面中,用户输入手机号后,点击“获取验证码”按钮,触发发送短信验证码的操作。可以使用如下代码示例: ```java private void sendVerificationCode(String phoneNumber) { PhoneAuthProvider.getInstance().verifyPhoneNumber( phoneNumber, 60, TimeUnit.SECONDS, this, new PhoneAuthProvider.OnVerificationStateChangedCallbacks() { @Override public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) { //自动验证 } @Override public void onVerificationFailed(@NonNull FirebaseException e) { //验证码发送失败 } @Override public void onCodeSent(@NonNull String verificationId, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) { //保存 verification ID,用于验证用户输入的验证码 mVerificationId = verificationId; } }); } ``` 4. 在登录页面中,用户输入手机号和验证码后,点击“登录”按钮,触发验证操作。可以使用如下代码示例: ```java private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) { FirebaseAuth.getInstance().signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { //登录成功 } else { //登录失败 } } }); } ``` 5. 在验证成功后,可以将用户信息保存到本地或者服务器上,以便下次登录时使用。 以上仅为简单的实现步骤,具体实现还需要考虑网络连接、异常处理等问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值