1.怎么使用别人的library
1.复制
2.
3.添加
4.解决在android 模块不出现library问题
2.App与library相互转换
步骤:
1.添加如下代码,这里都是字符串
2.修改
3.添加一个AndroidManifest.xml
作用:根据是app还是library来选择要使用哪个。 修改为这样 然后在添加这段代码,用于用哪个AndroidManifest.xml
4.怎么修改为library或APP呢
5.将APP修改为library后怎么使用呢?
1.导入
找到我们的包,再添加进去app
2.修改
将主app的gradle.properties添加如下,就可以了
3.遇到的问题
1.library中的id不再是常量:
case R.id.xxx爆红
解决办法:
选择switch,alt+enter 转为if
2.switch要改为if
@Override
public void onClick(View v
) {
switch (v
.getId()) {
case R
.id
.bt_share
:
if (mFile
== null
) {
Util
.toast(mContext
.getResources().getString(R
.string
.tip_save
));
break;
}
Util
.shareImage(mFile
);
break;
case R
.id
.iv_preview
:
mView
.startToolbarAnimator();
break;
case R
.id
.bt_save
:
if(!Util
.checkPermission(mContext
, Manifest
.permission
.WRITE_EXTERNAL_STORAGE
)) {
Util
.requestPermissions(mContext
, Manifest
.permission
.WRITE_EXTERNAL_STORAGE
);
break;
}
if (mState
!= State
.NONE
) {
Util
.toast(mContext
.getResources().getString(R
.string
.saved
));
break;
}
mState
= State
.SAVING
;
File file
= Util
.saveBitmap(mView
.getPreviewBitmap(), Constants
.PATH_DIR
);
mState
= State
.SAVED
;
if (file
!= null
) {
mFile
= file
;
Util
.toast(mContext
.getResources().getString(R
.string
.succeed_save
));
} else {
Util
.toast(mContext
.getResources().getString(R
.string
.failed_save
));
}
break;
}
}
改为if
@Override
public void onClick(View v
) {
int id
= v
.getId();
if (id
== R
.id
.bt_share
) {
if (mFile
== null
) {
Util
.toast(mContext
.getResources().getString(R
.string
.tip_save
));
return;
}
Util
.shareImage(mFile
);
} else if (id
== R
.id
.iv_preview
) {
mView
.startToolbarAnimator();
} else if (id
== R
.id
.bt_save
) {
if (!Util
.checkPermission(mContext
, Manifest
.permission
.WRITE_EXTERNAL_STORAGE
)) {
Util
.requestPermissions(mContext
, Manifest
.permission
.WRITE_EXTERNAL_STORAGE
);
return;
}
if (mState
!= State
.NONE
) {
Util
.toast(mContext
.getResources().getString(R
.string
.saved
));
return;
}
mState
= State
.SAVING
;
File file
= Util
.saveBitmap(mView
.getPreviewBitmap(), Constants
.PATH_DIR
);
mState
= State
.SAVED
;
if (file
!= null
) {
mFile
= file
;
Util
.toast(mContext
.getResources().getString(R
.string
.succeed_save
));
} else {
Util
.toast(mContext
.getResources().getString(R
.string
.failed_save
));
}
}
}
3.build.gradle 要保持一致
不然会很难受,各种未知的错误