附上两个Activiy的部分代码
public class MainActivity extends BaseActivity implements TabLayout.OnTabSelectedListener, IMutualListener {
private ViewPager mViewPager ;
private TabLayout mTabLayout ;
private View tabView = null;
private List<String> mTabList = new ArrayList<>();
private MainFragmentAdapter mFragmentAdapter;
private List<Fragment> mFragments = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mViewPager = findViewById(R.id.home_ViewPager);
mTabLayout = findViewById(R.id.tab_layout);
}
private int[] tabIcons = {
R.mipmap.selector_home_normal,
R.mipmap.selector_alarm_normal,
R.mipmap.selector_mine_normal,
R.mipmap.selector_more_normal,
};
private int[] tabIconsPressed = {
R.mipmap.selector_home_pressed,
R.mipmap.selector_alarm_pressed,
R.mipmap.selector_mine_pressed,
R.mipmap.selector_more_pressed,
};
@Override
public int getContentViewId(){
return R.layout.activity_main;
}
@Override
public void initViews() {
receiveAdDownload();
initFragmentList();
initFragments();
initLabeView();
}
private void initLabeView() {
initBadgeViews();
}
private void initBadgeViews() {
}
private void initTabList(){
mTabList.clear();
mTabList.add(MyApplication.getAppResources().getString(R.string.home));
mTabList.add(MyApplication.getAppResources().getString(R.string.alarm));
mTabList.add(MyApplication.getAppResources().getString(R.string.mine));
mTabList.add(MyApplication.getAppResources().getString(R.string.more));
}
private void initFragmentList(){
mFragments.clear();
mFragments.add(HomeFragment.getInstance(MyApplication.getAppResources().getString(R.string.home)));
mFragments.add(AlarmFragment.getInstance(MyApplication.getAppResources().getString(R.string.alarm)));
mFragments.add(MineFragment.getInstance(MyApplication.getAppResources().getString(R.string.mine)));
mFragments.add(MineFragment.getInstance(MyApplication.getAppResources().getString(R.string.more)));
}
private void initFragments() {
initTabList();
mFragmentAdapter = new MainFragmentAdapter(getSupportFragmentManager(), mTabList, getApplicationContext(), mFragments);
mViewPager.setAdapter(mFragmentAdapter);
mViewPager.setCurrentItem(0);
mTabLayout.setupWithViewPager(mViewPager);
mTabLayout.setTabMode(TabLayout.MODE_FIXED);
mTabLayout.addOnTabSelectedListener(this);
mTabLayout.getTabAt(0).setCustomView(getTabView(0));
mTabLayout.getTabAt(1).setCustomView(getTabView(1));
mTabLayout.getTabAt(2).setCustomView(getTabView(2));
mTabLayout.getTabAt(3).setCustomView(getTabView(3));
}
public abstract class BaseActivity<P extends BasePresenter> extends AppCompatActivity implements UIInitA {
protected P mPresenter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (null != onCreatePresenter()){
mPresenter =onCreatePresenter();
}
AppManager.newInstance().addActivivty(this);
setContentView(getContentViewId());
initViews();
addListener();
initData();
}