androidannotations 在android studio中的使用
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>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。