一直就想完成这个工作. 这次一定要抽出时间完成, yes, this time.
本文的合集已经编著成书,高级Android开发强化实战,欢迎各位读友的建议和指导。在京东即可购买:https://item.jd.com/12385680.html
参考以前的文章, 又添加若干新内容.
修改统一的版本配置, chunyu_base.gradle
.
android {
compileSdkVersion 22
defaultConfig {
targetSdkVersion 22
}
}
dependencies {
compile 'com.android.support:appcompat-v7:22.0.0'
}
错误
Error:(11, 32) No resource found that matches the given name
(at 'layout_height' with value '@dimen/abc_action_bar_default_height').
替换ActionBar的高度为Android5.0属性, 即
android:layout_height="@dimen/abc_action_bar_default_height"
为
android:layout_height="?attr/actionBarSize"
位置: activity_volunteer_doctor_list.xml 和 activity_offline_clinic_list.xml
错误:
java.lang.NullPointerException:
Attempt to invoke virtual method
'void me.chunyu.ChunyuDoctor.home.HomeAssistantNewsFragment.setAct(android.app.Activity)'
on a null object reference
at me.chunyu.ChunyuDoctor.home.MainPageFragment.initView(MainPageFragment.java:244)
原因G7Anno出现问题, 应该使用fragment.getChildFragmentManager
.
public android.support.v4.app.Fragment getV4Fragment(android.support.v4.app.Fragment fragment,
int fragmentId, android.support.v4.app.Fragment defaultFrag) {
android.support.v4.app.Fragment frag =
fragment.getFragmentManager().findFragmentById(fragmentId);
return frag == null ? defaultFrag : frag;
}
修改后
public android.support.v4.app.Fragment getV4Fragment(android.support.v4.app.Fragment fragment,
int fragmentId, android.support.v4.app.Fragment defaultFrag) {
fragment.getChildFragmentManager().findFragmentById(fragmentId);
android.support.v4.app.Fragment frag = null;
if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
frag = fragment.getChildFragmentManager().findFragmentById(fragmentId);
} else {
frag = fragment.getFragmentManager().findFragmentById(fragmentId);
}
return frag == null ? defaultFrag : frag;
}
替换G7Anno-Core
compile 'me.chunyu.android:g7anno-core:0.1.7-rc1@jar'
为
compile 'me.chunyu.android:g7anno-core-v22:0.1.0@jar'
修改G7Anno-Lib, 适配Fragment嵌套.
@Override
public void onDestroyView() {
super.onDestroyView();
// 导致加载嵌套的Fragment异常, 删除View的操作, 移至创建View的时候.
// View v = mContentView.get();
// if (v != null && v.getParent() != null) {
// ((ViewGroup) v.getParent()).removeView(v);
// }
}
OK, that's all! Enjoy it!