一,首先就是两个页面布局
1,登录页面的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <EditText android:id="@+id/phone" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dp" android:gravity="center" android:hint="请输入手机号" /> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dp" android:gravity="center" android:hint="请输入密码" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dp" android:gravity="center" android:orientation="horizontal"> <Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="登录" /> <Button android:id="@+id/reg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="注册" /> </LinearLayout> </LinearLayout>
2,注册页面的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <EditText android:id="@+id/phone" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dp" android:gravity="center" android:hint="请输入手机号" /> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dp" android:gravity="center" android:hint="请输入密码" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dp" android:gravity="center" android:orientation="horizontal"> <Button android:id="@+id/reg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="注册" /> </LinearLayout> </LinearLayout>
二,拿到登录和注册的接口,分别请求,创建出实体bean类。
1,登录bean类
public class LoginBean { /** * msg : 登录成功 * code : 0 * data : {"age":null,"appkey":"9cdef4b09eb65685","appsecret":"66B6E2E5F439618D01B67FBAEA31EFDA","createtime":"2018-01-15T16:19:03","email":null,"fans":null,"follow":null,"gender":null,"icon":null,"latitude":null,"longitude":null,"mobile":"18765432100","money":null,"nickname":null,"password":"473344696F4685CAE5B5B3C354BC77BE","praiseNum":null,"token":"AFD92DF6C6046F01B76D7C551AEC985B","uid":4362,"userId":null,"username":"18765432100"}