知识点
requestWindowFeature 是用来设置全屏 或者设置标题上的进度条
设置窗口特征 在标题上显示进度条
启用显示进度条: requestWindowFeature(Window.FEATURE_PROGRES);
启用不显示进度条 :requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
Activity中
this.requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature 必须在Activity.setContentView()之前调用,否则无效。
BaseActivity .java
onCreate 方法设置窗体属性 并给活动加xml 子类覆盖getLayoutId()方法设置xml
子类覆盖initView方法
onCreate(Bundle savedInstanceState) {
.onCreate(savedInstanceState);
requestWindowFeature(Window.);
= ;
(getLayoutId() != ) {
setContentView(getLayoutId());
}
initView(savedInstanceState);
}
MainACtivity 继承baseActivyity
initView(Bundle savedInstanceState) {
= (RadioGroup)findViewById(R.id.);
setFragmentManager();
.setOnCheckedChangeListener(RadioGroup.OnCheckedChangeListener() {
onCheckedChanged(RadioGroup group, checkedId) {
setFragmentManager(checkedId);
}
});
}
setFragmentManager(checkedId){
= getSupportFragmentManager();
FragmentTransaction fragmentTransaction = .beginTransaction();
Fragment fragment = FragmentFactory.(checkedId);
fragmentTransaction.replace(R.id.,fragment);
fragmentTransaction.commit();
}
getLayoutId() {
R.layout.;
}
FragmentFactory Fragment的生产工厂根据 值创建不同的Fragment
FragmentFactory {
Fragment getInstanceByIndex(index){
Fragment fragment = ;
(index){
:
fragment = MainFragment();
;
:
fragment = ServerFragment();
;
:
fragment = BbsFragment();
;
:
fragment = MapFragment();
;
}
fragment;
}
}
baseFragment
View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
= inflater.inflate(getLayoutId(), );
;
}
onActivityCreated(Bundle savedInstanceState) {
.onActivityCreated(savedInstanceState);
initView(savedInstanceState);
}
BaseActivity onCreate() getLayoutId() -->MainActivity 覆盖 的到 R.layout.fragment-->继续回到 BaseActivity setContentView (此时对象是MainActivity,相当于MainACtivity.setContentView) -->MainActivity initView方法覆盖
-->MainACtivity setFragmentManager(1) 传默认的fragment坐标-->MainActivity setFragment(int)方法-->调用 FragmentFactory类 getInstanceByiIndex(int)-->通过(int)返回所需要的fragment--> BaseFragment onCreateView 通过getLayoutId()-->MainFragment getLayoutId()覆盖 返回fragment_main-->返回 view -->BaseFragment onActivityCreated 方法中 -->MainFragment 覆盖initView()走完流程。。。