Activity 之继承学习 Fragment

知识点

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()走完流程。。。

转载于:https://my.oschina.net/Dougien/blog/605769

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值