androidannotations 在android studio中的使用

來源:互聯網
上載者:User

標籤:

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.2dependencies {    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中的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.