美文网首页
AndroidAnnotations--依赖注入

AndroidAnnotations--依赖注入

作者: radish520like | 来源:发表于2016-08-15 19:48 被阅读0次

主页: http://androidannotations.org/

AndroidAnnotations的优点
1.使用依赖注入Views,extras,System Service,resources
2.简化线程模型
3.事件绑定
4.REST Client

使用:
依赖配置比较繁琐,直接上图
1.在project/build.gralde文件中添加如下代码
mavenCentral()

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

mavenCentral()
mavenLocal()
Paste_Image.png

2.在app/build.gradle文件中添加如下代码

apply plugin: 'android-apt'

apt {
    arguments {
        androidManifestFile variant.outputs[0]?.processResources?.manifestFile
    }
}

apt "org.androidannotations:androidannotations:4.0.0"
compile "org.androidannotations:androidannotations-api:4.0.0"

![Uploading Paste_Image_617775.png . . .]

Paste_Image.png Paste_Image.png

注意事项:清单文件中注册的activity要在原类名之后追加下划线"_",使用注解的控件和方法不能被private修饰符修饰,该框架大型项目并不适用

可在Activity上添加注入代码
@Fullscreen //全屏
@WindowFeature(Window.FEATURE_NO_TITLE)//无标题
@EActivity(R.layout.my_activity) //在这里声明布局文件,不用setContentView()

//初始化控件
@ViewById(R.id.myTextView)
TextView textView
//字符串资源
@StringRes(R.string.app_name)
String appName;
//颜色资源
@ColorRes(R.color.colorAccent)
int androidColor;
//系统服务
@SystemService
NotificationManager notificationManager;
//事件控制,以按钮的id作为方法名
@Click
void myButtonClicked(){}
@Click(R.id.button)
void submit(){}
//开启新线程后台运行,注意不要引用UI控件,并且返回值类型一定是void
@Background
void someBackgroundWork(){}
//UiThread//UI线程
void updateUi(){}

相关文章

  • AndroidAnnotations--依赖注入

    主页: http://androidannotations.org/ AndroidAnnotations的优点1...

  • 开源项目的依赖注入

    开源项目的依赖注入 依赖注入概念 依赖注入(DI:Dependency Injection): 依赖注入方式: B...

  • 资料收集

    依赖注入 AngularJs依赖注入的研究 (已读) 依赖注入(已读)

  • Dagger2常用注解诠释

    依赖注入 控制反转(IoC)与依赖注入(DI)浅谈依赖注入理解依赖注入(IOC)和学习Unity Gradle配置...

  • Day62 Spring 依赖注入源码解析

    手动注入自动注入 依赖注入,set注入,构造注入 依赖注入: Key依据 byType byName constr...

  • Dagger2 源码分析

    Dagger简单介绍 Dagger2涉及到依赖注入,有关依赖注入的请到理解依赖注入 通过注解方式实现依赖注入分为两...

  • 依赖注入(转)

    依赖注入(转) 原文地址:依赖注入原理

  • Spring学习之依赖注入

    Spring学习之依赖注入 依赖注入的基本概念 依赖注入(Dependecy Injection),也称为IoC(...

  • 依赖注入及Dagger2框架简介

    依赖注入简介 在介绍Dagger框架之前我们先来看看依赖注入(Dependence Injection),依赖注入...

  • 浅谈依赖注入

    依赖注入是什么? 依赖注入的作用是什么? 依赖注入的应用场景? 如何实现依赖注入? 对于一个后端程序员来说,依赖注...

网友评论

      本文标题:AndroidAnnotations--依赖注入

      本文链接:https://www.haomeiwen.com/subject/ddgusttx.html