码迷,mamicode.com
首页 > 移动开发 > 详细

androidannotations 在android studio中的使用

时间:2015-05-25 11:42:27      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

apply plugin: ‘com.android.application‘

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.change360.helpdoctor"
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘
        }
    }
}

dependencies {
    compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])
    compile ‘com.android.support:appcompat-v7:22.1.1‘
    compile ‘com.github.rey5137:material:1.1.0‘
    compile ‘de.greenrobot:eventbus:2.4.0‘
    compile ‘net.steamcrafted:load-toast:1.0.6‘
}
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        // replace with the current version of the Android plugin
        classpath ‘com.android.tools.build:gradle:1.2.2‘
        // the latest version of the android-apt plugin
        classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.4‘
    }
}

repositories {
    mavenCentral()
    mavenLocal()
}
apply plugin: ‘android-apt‘
def AAVersion = ‘3.3.1‘ // change this to your desired version, for example the latest stable: 3.2

dependencies {
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
}


apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        // if you have multiple outputs (when using splits), you may want to have other index than 0

        // If you‘re using flavors you should use the following line instead of hard-coded packageName
        // resourcePackageName android.defaultConfig.packageName

        // You can set optional annotation processing options here, like these commented options:
        // logLevel ‘INFO‘
        // logFile ‘/var/log/aa.log‘
    }
}

上面是在android studio里面的build.gradle文件

下面是Activity中的使用,是不是比以前更清爽了。


import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu;
import org.androidannotations.annotations.ViewById;

@OptionsMenu(R.menu.menu_main)
@EActivity(R.layout.activity_main)
public class MainActivity extends ActionBarActivity {


    @ViewById
    TextView textView;
    @AfterViews
    public  void init(){
        textView.setText("hello world");
    }
    @OptionsItem(R.id.action_settings)
    void myMethod() {
        // You can specify the ID in the annotation, or use the naming convention
    }
}


注意:最后在配置Activity的时候一定要在原有的基础上加上_(配置中是MainActivity_而不是MainActivity

下面是配置文件

<activity
    android:name=".MainActivity_"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>




androidannotations 在android studio中的使用

标签:

原文地址:http://my.oschina.net/cng1985/blog/419423

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!