package com.wangbb.naruto.app.fragment;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.wangbb.naruto.R;
import com.wangbb.naruto.app.activity.MainActivity;
import com.wangbb.naruto.app.adapter.TabFragmentPagerAdapter;
import com.wangbb.naruto.app.fragment.childFragment.ChildOneFragment;
import com.wangbb.naruto.app.fragment.childFragment.ChildThreeFragment;
import com.wangbb.naruto.app.fragment.childFragment.ChildTwoFragment;
import com.wangbb.naruto.app.view.PagerSlidingTabStrip;
/**
* Created by wangbinbin on 15/5/9.
*/
public class MainTempFragment extends BaseFragment {
private MainActivity mainActivity;
private View view;
private PagerSlidingTabStrip indicator;
private ViewPager viewpager;
private int currentIndex = 0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_main_temp, container, false);
initView();
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
this.mainActivity = (MainActivity) getActivity();
}
private void initView() {
Class[] fragments = new Class[]{ChildOneFragment.class,
ChildTwoFragment.class, ChildThreeFragment.class};
String[] text = {"One", "Two", "Three"};
// int[] icons = {R.drawable.overseas_service_onddaytour_tab_selector,
// R.drawable.overseas_service_entrancetick_selector,
// R.drawable.overseas_service_tab_trafic_selecter};
indicator = (PagerSlidingTabStrip) view
.findViewById(R.id.viewpager_indicator);
setTabsValue();
TabFragmentPagerAdapter adapter = new TabFragmentPagerAdapter(
getChildFragmentManager(), getActivity(), fragments, text,
null, 1);
viewpager = (ViewPager) view
.findViewById(R.id.viewpager);
viewpager.setAdapter(adapter);
viewpager.setOffscreenPageLimit(5);
indicator.setViewPager(viewpager);
indicator.setCurrentItem(currentIndex);
}
/**
* ��PagerSlidingTabStrip�ĸ������Խ��и�ֵ��
*/
private void setTabsValue() {
DisplayMetrics dm = getResources().getDisplayMetrics();
// ����Tab���Զ��������Ļ��
indicator.setShouldExpand(true);
// ����Tab�ķָ���������
indicator.setDividerColor(getResources().getColor(android.R.color.transparent));
indicator.setDividerPadding((int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 8, dm));
// ����Tab�ײ��ߵĸ߶�
indicator.setUnderlineHeight((int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 2, dm));
// ����Tab Indicator�ĸ߶�
indicator.setIndicatorHeight((int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 4, dm));
// ����Tab�������ֵĴ�С
indicator.setTextSize((int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, 13, dm));
indicator.setTextColorResource(R.color.indicator_tab_main_text_color);
// ����Tab Indicator����ɫ
indicator.setIndicatorColor(getResources().getColor(
R.color.color_339999));
// // ����ѡ��Tab���ֵ���ɫ (�������Զ����һ������)
// indicator.setSelectedTextColor(getResources().getColor(
// R.color.light_purple_color));
// ȡ�����Tabʱ�ı���ɫ
// indicator.setTabBackground(0);
indicator.setLinePadding((int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 10, dm));
indicator.setIconHeight((int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 20, dm));
}
}