Android开发中通过手机号开发中通过手机号+短信验证码登录的实例代码短信验证码登录的实例代码
最近在开发一个android的项目,需要通过获取手机验证码来完成登录功能,接下来通过实例代码给大家分享手
机号+短信验证码登录的实现方法,需要的的朋友参考下吧
首先,需要一个电话号码,目前很多账户都是将账户名设置成手机号,然后点击按钮获取手机验证码。
其次,你需要后台给你手机短信的验证接口,各个公司用的不一样,这个身为前端,不需要你来考虑,你只要让你后台给你写
好接口,你直接调用就好了。
activity_login.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:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="@+id/mobile_login"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:hint="请输入您的手机号"
android:textSize="16sp"
android:background="@null"
android:inputType="number"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="@+id/yanzhengma"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="4"
android:background="@null"
android:layout_marginLeft="10dp"
android:hint="请输入验证码"
android:textSize="16sp"
android:inputType="number"
/>
<Button
android:id="@+id/getyanzhengma1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.9"
android:textSize="13sp"
android:gravity="center"
android:text="获取验证码"
android:layout_gravity="center"
/>
</LinearLayout>
<Button
android:id="@+id/login_btn"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="登录"
android:textSize="16sp"
/>
</LinearLayout>
评论1