AndroidAnnotations是一个能够让你快速进行Android开发的开源框架,它能让你专注于真正重要的地方。AndroidAnnotations使代码更加精简,使项目更加容易维护,它的目标就是Fast Android Development. Easy maintainance。
使用AndroidAnnotations,相比原生的Android开发,确实能够让你少写很多代码,它的首页也给出了一个简单
的例子,通过例子也可以看到代码比之前几乎少写了一半。
AndroidAnnotations官方主页:http://androidannotations.org/
首先,看看AndroidAnnotations如何集成。
1、到官网下载AndroidAnnotations的jar包,本文使用的是AndroidAnnotations 3.0.1版本。
解压后将androidannotations-3.0.1.jar加入项目的libs目录。
2、配置Eclipse
(1)项目右键选择Properties,选择Java Compiler,确保编译器版本为1.6。
(2)Java Compiler -> Annotation Processing -> Enable annotation processing
(3)Java Compiler -> Annotation Processing -> Enable annotation processing -> Factory Path -> 添加androidannotations-3.0.1.jar
(4)Project -> Clean
接下来,给出一个简单的例子,通过这个例子,可以对AndroidAnnotations的使用有个初步的了解。
activity_main.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:background="@color/gray_bg" android:orientation="vertical" > <TextView android:id="@+id/titleTextView" android:layout_width="match_parent" android:layout_height="45.0dp" android:background="@color/titlebar_bg" android:gravity="center" android:singleLine="true" android:textColor="@color/white" android:textSize="22.0sp" android:textStyle="normal" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10.0dp" android:background="@drawable/frame" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal" android:padding="10.0dp" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon_touxiang" /> <TextView android:layout_width="60.0dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginLeft="10.0dp" android:text="账号:" android:textColor="@color/text_black" android:textSize="15.0sp" /> <EditText android:id="@+id/nameEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@null" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1.0px" android:background="@color/line_normal" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal" android:padding="10.0dp" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon_mima" /> <TextView android:layout_width="60.0dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginLeft="10.0dp" android:text="密码:" android:textColor="@color/text_black" android:textSize="15.0sp" /> <EditText android:id="@+id/passwordEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@null" android:password="true" /> </LinearLayout> </LinearLayout> <TextView android:id="@+id/loginTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="20.0dp" android:layout_marginLeft="10.0dp" android:layout_marginRight="10.0dp" android:layout_marginTop="10.0dp" android:background="@drawable/blue_bground" android:gravity="center" android:padding="10.0dp" android:text="登录" android:textColor="@color/white" android:textSize="15.0sp" /> </LinearLayout>
MainActivity.java
package com.eric.annotation; import org.androidannotations.annotations.AfterViews; import org.androidannotations.annotations.Click; import org.androidannotations.annotations.EActivity; import org.androidannotations.annotations.ViewById; import android.app.Activity; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; @EActivity(R.layout.activity_main) public class MainActivity extends Activity { @ViewById TextView titleTextView; @ViewById EditText nameEditText; @ViewById EditText passwordEditText; @ViewById TextView loginTextView; @AfterViews void updateTitle() { titleTextView.setText("Annotation"); } @Click void loginTextView() { Toast.makeText(getApplicationContext(), "name:" + nameEditText.getText() + "\npassword:" + passwordEditText.getText(), Toast.LENGTH_SHORT ).show(); } }
注意:AndroidManifest.xml文件里的Activity的名字都要在原来的基础上加一个下划线 。例如:
<activity android:name="com.eric.annotation.MainActivity"></activity>
改成
<activity android:name="com.eric.annotation.MainActivity_"></activity>
相关推荐
AndroidAnnotations注解的基本使用,适合于初学者学习使用
Android 注解入门,方便以后的学习,提高代码开发效率。
使用AndroidAnnotations框架制作类似微信界面切换的功能,在一个Activity使用viewpager 切换fragment . 附带AndroidAnnotations 的jar包.
androidannotations框架举例
androidannotations 注解框架的配置及使用教程,注解框架androidannotations从入门到放弃的一个小demo。
AndroidAnnotations包要放到app/compile-libs(要自己建立该目录)下(可以不使用),AndroidAnnotations-api该包要放到app/libs。
使用AndroidAnnotations框架优雅地实现ListView功能例子完整源代码。代码精简,可读性强,实在是android入门listview的必备代码。
AndroidAnnotations 是如何工作的 使用注解的方式开发android,极大提高了开发效率
Android注释-教程RSS 什么是Android注释? Android Annotations是一个开放源代码框架,其前提很简单:代码饮食。 他负责为您实施重复性...首先,我们必须获取Android批注,为此,我们必须使用Android Studio构建系统,
有积分的兄弟帮忙下这个,我赚点积分,谢谢 ... 使用AndroidAnnotations框架优雅地实现ListView功能例子完整源代码。代码精简,可读性强,实在是android入门listview的必备代码。
使用AndroidAnnotations框架优雅地实现ListView功能例子源代码.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
属于android的一个开源库,很好使用,会给开发带来不一样的便利
AndroidAnnotations-Sample-App 使用 AndroidAnnotations 系统的示例应用程序,以实现更易读、更易于维护和更快地编写代码。 它随附博客文章第 1 部分 - 描述 AndroidAnnotations: ://snowdog.co/blog/...
Androidannotation使用之@Rest与服务器交互的JSON数据转换
香料注解 这是一个简单的应用程序,展示了如何在一个项目中同时使用 AndroidAnnotations 和 RoboSpice 框架。
功能:完全注解框架,一切皆为注解:声明控件,绑定控件,...缺点:文档是全英文的加上功能比较少没有具体研究,由于一切都是注解,感觉效率不高,不过根据官方介绍说并不是使用的反射加载,所以效率比一般注解高很多。
带有 androidannotations、multidex 和 scala 插件的示例 gradle android 项目。 从 Android Studio 1.0.1 运行正常 该项目最初是为了解决警告而创建的,该警告已由。 配置 您可能需要使用指向 sdk 安装的指针在项目...
android demo,annotations4.4.0和android studio3.0.1的配置使用的实现。实现了一个textview和button的title的设置和onclick的编写。
制作这个项目是为了说明并为我介绍AndroidAnnotations的演讲提供一个例子。 与演讲相关的幻灯片可以在访问。 ##Configuration 要使用此应用程序,唯一需要的配置是更改类中的 League of Lengeds API Key。 您可以...