使用Rxjava和Retrofit实现登录注册


需要使用的依赖和权限

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
compileSdkVersion rootProject.ext.android.compileSdkVersion

defaultConfig {
    applicationId "com.bwie.test.mymvp_demo"
    minSdkVersion rootProject.ext.android.minSdkVersion
    targetSdkVersion rootProject.ext.android.targetSdkVersion
    versionCode rootProject.ext.android.versionCode
    versionName rootProject.ext.android.versionName
}
implementation rootProject.ext.dependencies[ "appcompat-v7"]implementation rootProject.ext.dependencies[ "constraint-layout"]implementation rootProject.ext.dependencies[ "retrofit2"]implementation rootProject.ext.dependencies[ "converter-gson"]implementation rootProject.ext.dependencies[ "rxjava2"]implementation rootProject.ext.dependencies[ "rxjava2:rxandroid"]implementation rootProject.ext.dependencies[ "dagger"]annotationProcessor rootProject.ext.dependencies[ "dagger-compiler"]implementation rootProject.ext.dependencies[ "adapter-rxjava"]implementation 'com.facebook.fresco:fresco:0.12.0' // 支持 GIF 动图,需要添加implementation 'com.facebook.fresco:animated-gif:0.12.0'implementation 'com.android.support:support-v4:27.1.1'

在build.gradle存放

apply from: "config.gradle"
buildscript {
 
}

需要在项目下创建一个config.gradle文件,使用时将application的路径名改成自己的

ext {
    android = [
            compileSdkVersion: 27,
            applicationId    : "com.bwie.test.mymvp_demo",
            minSdkVersion    : 15,
            targetSdkVersion : 27,
            versionCode      : 1,
            versionName      : "1.0"
    ]

    dependencies = [
            "appcompat-v7"     : "com.android.support:appcompat-v7:27.1.1",
            "constraint-layout": "com.android.support.constraint:constraint-layout:1.1.0",
            "retrofit2"        : "com.squareup.retrofit2:retrofit:2.4.0",
            "converter-gson"   : "com.squareup.retrofit2:converter-gson:2.4.0",
            "adapter-rxjava"  :  "com.squareup.retrofit2:adapter-rxjava2:2.4.0",
            "rxjava2"          : "io.reactivex.rxjava2:rxjava:2.1.13",
            "rxjava2:rxandroid": "io.reactivex.rxjava2:rxandroid:2.0.2",
            "dagger"           : "com.google.dagger:dagger:2.8",
            "dagger-compiler" : "com.google.dagger:dagger-compiler:2.7"

    ]
}

activity_login

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".LoginActivity">
    <RelativeLayout
        android:id="@+id/login_title_relative"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp">

        <ImageView
            android:id="@+id/cha"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:src="@drawable/cha"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="京东登录"/>

    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/login_title_relative"
        android:layout_margin="10dp"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="账号"/>

            <EditText
                android:id="@+id/mobile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="密码"/>

            <EditText
                android:id="@+id/password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>

        <Button
            android:id="@+id/btLogin"
            android:text="登录"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值