xUtils3.0的使用(一)IOC
首先,没啥说的,放上xUtils的github地址:
https://github.com/wyouflf/xUtils3
作者的原话:xUtils3api变化较多;
xUtils2.x对Android6.0兼容不是很好,请尽快升级至xUtils3;
xUtils最低兼容Android4.0(apilevel14);(各位同学记得要留意自己项目的minsdk,低于14运行会报错的)
数据库api简化提高性能,达到和greenDao一致的性能.
......
本文浅谈一下IOC的用法
一.使用前配置
需要的权限:<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />初始化:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
x.Ext.init(this);
x.Ext.setDebug(BuildConfig.DEBUG);
//是否输出debug日志,开启debug会影响性能.(这行代码可要可不要)
}
}写好MyApplicaton后还要在AndroidManifest.xml中通过android:name属性指定这个application:
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>二.开始使用@ContentView(R.layout.activity_main)
public class MainActivity extends AppCompatActivity {
@ViewInject(R.id.fab)
private FloatingActionButton button;
//这里注意,变量和方法一定要是私有的(private)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
x.view().inject(this);
//类似开启xUtils注入的功能
}
@Event(R.id.fab) //参数支持数组 value={id1, id2, id3}
private void clickMe(View view){
Snackbar.make(view,"ioc succeed!",Snackbar.LENGTH_SHORT).show();
}
}总体来说,使用方法和ButterKnife相似。
相关推荐
itjavashuai 2020-07-28
smalllove 2020-07-27
willluckysmile 2020-06-29
TiDBPingCAP 2020-06-21
丽丽 2020-06-11
shenxiuwen 2020-06-10
willluckysmile 2020-06-10
MrFuWen 2020-06-09
yuanye0 2020-06-08
whbing 2020-05-19
yuanye0 2020-05-14
kong000dao0 2020-05-10
方志朋 2020-05-08
somyjun 2020-05-01
suixinsuoyu 2020-04-29
咻pur慢 2020-04-22
tianxiaolu 2020-04-06
吾日五省我身 2020-03-28