需要使用的依赖和权限
<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"/> <