| | |
| | | package cn.com.basic.face.base; |
| | | |
| | | import android.content.Context; |
| | | import android.support.design.widget.TabLayout; |
| | | import android.support.v4.app.Fragment; |
| | | import android.support.v4.app.FragmentManager; |
| | | import android.support.v4.app.FragmentPagerAdapter; |
| | | import android.support.v4.view.ViewPager; |
| | | import android.os.Bundle; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.widget.ImageView; |
| | | import android.widget.TextView; |
| | | |
| | | import com.bsk.zhangbo.demoforbsk.R; |
| | | import cn.com.basic.face.adapter.MyFragmentPagerAdapter; |
| | | import cn.com.basic.face.fragment.SurveillanceFragment; |
| | | import cn.com.basic.face.util.TabNameUtil; |
| | | import cn.com.basic.face.fragment.AttendanceFragment; |
| | |
| | | import cn.com.basic.face.fragment.RegisterFragment; |
| | | import cn.com.basic.face.fragment.VisitFragment; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | |
| | | public static MainActivity getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public static class MyFragmentPagerAdapter extends FragmentPagerAdapter { |
| | | |
| | | private final List<Fragment> mFragments = new ArrayList<>(); |
| | | private final List<String> mFragmentTitles = new ArrayList<>(); |
| | | private final List<Integer> mFragmentIcons = new ArrayList<>(); |
| | | private Context context; |
| | | public MyFragmentPagerAdapter(FragmentManager fm, Context context) { |
| | | super(fm); |
| | | this.context = context; |
| | | } |
| | | |
| | | public void addFragment(Fragment fragment, String title,int drawable) { |
| | | mFragments.add(fragment); |
| | | mFragmentTitles.add(title); |
| | | mFragmentIcons.add(drawable); |
| | | } |
| | | |
| | | @Override |
| | | public Fragment getItem(int position) { |
| | | return mFragments.get(position); |
| | | } |
| | | |
| | | @Override |
| | | public int getCount() { |
| | | return mFragments.size(); |
| | | } |
| | | |
| | | @Override |
| | | public CharSequence getPageTitle(int position) { |
| | | return null; |
| | | } |
| | | |
| | | public View getTabView(int position){ |
| | | View view = LayoutInflater.from(context).inflate(R.layout.activity_main_tab,null); |
| | | TextView mTvTitle = (TextView) view.findViewById(R.id.tab_item_title); |
| | | mTvTitle.setText(mFragmentTitles.get(position)); |
| | | ImageView mImgIcon = (ImageView) view.findViewById(R.id.tab_item_icon); |
| | | mImgIcon.setImageResource(mFragmentIcons.get(position)); |
| | | return view; |
| | | } |
| | | |
| | | } |
| | | |
| | | } |