Exemplo n.º 1
0
  public void initView() {
    setContentView(R.layout.activity_home);
    StatusBarCompat.compat(this, ResourcesUtils.getResColor(this, R.color.colorPrimaryDark));
    ButterKnife.bind(this);

    initTabView();
  }
Exemplo n.º 2
0
  private void initTabView() {

    tabTiles = ResourcesUtils.getStringArray(this, R.array.tabItemName);
    tabItemDrawableNormal =
        new int[] {
          R.drawable.ic_tab_home_normal,
          R.drawable.ic_tab_classification_normal,
          R.drawable.ic_tab_car_normal,
          R.drawable.ic_tab_personal_normal
        };
    tabItemDrawableSelected =
        new int[] {
          R.drawable.ic_tab_home_selected,
          R.drawable.ic_tab_classification_selected,
          R.drawable.ic_tab_car_selected,
          R.drawable.ic_tab_personal_selected
        };

    final HomeActFragAdpter fragAdapter =
        new HomeActFragAdpter(getSupportFragmentManager(), this, tabTiles, tabItemDrawableNormal);
    viewPager_content.setAdapter(fragAdapter);
    layout_buttom_tab.setupWithViewPager(viewPager_content);
    tabCount = layout_buttom_tab.getTabCount();
    for (int i = 0; i < tabCount; i++) {
      TabLayout.Tab tab = layout_buttom_tab.getTabAt(i);
      if (tab != null) {
        tab.setCustomView(fragAdapter.getTabView(i));
      }
    }
    viewPager_content.addOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          @Override
          public void onPageSelected(int position) {
            for (int i = 0; i < tabCount; i++) {
              TabLayout.Tab tab = layout_buttom_tab.getTabAt(i);
              AppCompatTextView textView = (AppCompatTextView) tab.getCustomView();
              if (i == position) {
                fragAdapter.changeSelecteTabColor(textView, tabItemDrawableSelected[i], true);
              } else {
                fragAdapter.changeSelecteTabColor(textView, tabItemDrawableNormal[i], false);
              }
            }
          }

          @Override
          public void onPageScrollStateChanged(int state) {}
        });
    viewPager_content.setCurrentItem(0);
    fragAdapter.changeSelecteTabColor(
        (AppCompatTextView) layout_buttom_tab.getTabAt(0).getCustomView(),
        tabItemDrawableSelected[0],
        true);
  }