private void addTab(CharSequence text, int index) {
   final TabView tabView = new TabView(getContext());
   tabView.mIndex = index;
   tabView.setFocusable(true);
   tabView.setOnClickListener(mTabClickListener);
   tabView.setText(text);
   mTabLayout.addView(tabView, new LinearLayout.LayoutParams(WRAP_CONTENT, FILL_PARENT, 1));
 }
 public void onClick(View view) {
   TabView tabView = (TabView) view;
   final int oldSelected = mViewPager.getCurrentItem();
   final int newSelected = tabView.getIndex();
   mViewPager.setCurrentItem(newSelected);
   if (oldSelected == newSelected && mTabReselectedListener != null) {
     mTabReselectedListener.onTabReselected(newSelected);
   }
 }
示例#3
0
  private void addTab(String text, Drawable icon, int index) {
    // Workaround for not being able to pass a defStyle on pre-3.0
    final TabView tabView = (TabView) mInflater.inflate(R.layout.vpi__tab, null);
    tabView.init(this, text, icon, index);
    tabView.setFocusable(true);
    tabView.setOnClickListener(mTabClickListener);

    mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1));
  }
 public void onClick(View view) {
   TabView tabView = (TabView) view;
   tabView.getTab().select();
   final int tabCount = mTabLayout.getChildCount();
   for (int i = 0; i < tabCount; i++) {
     final View child = mTabLayout.getChildAt(i);
     child.setSelected(child == view);
   }
 }
示例#5
0
 @Override
 public void onClick(View view) {
   if (!mPagingEnabled) return;
   final TabView tabView = (TabView) view;
   if (mCurrentItem == tabView.getIndex()) {
     mAdapter.onPageReselected(mCurrentItem);
   }
   mCurrentItem = tabView.getIndex();
   mViewPager.setCurrentItem(mCurrentItem);
 }
 public void addTab(ActionBar.Tab tab, boolean setSelected) {
   TabView tabView = createTabView(tab, false);
   mTabLayout.addView(tabView, new IcsLinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1));
   if (mTabSpinner != null) {
     ((TabAdapter) mTabSpinner.getAdapter()).notifyDataSetChanged();
   }
   if (setSelected) {
     tabView.setSelected(true);
   }
   if (mAllowCollapse) {
     requestLayout();
   }
 }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   if (convertView == null) {
     convertView = createTabView((ActionBar.Tab) getItem(position), true);
   } else {
     ((TabView) convertView).bindTab((ActionBar.Tab) getItem(position));
   }
   return convertView;
 }
  @Override
  public void setCurrentItem(int item) {
    if (mViewPager == null) {
      throw new IllegalStateException("ViewPager has not been bound.");
    }
    mSelectedTabIndex = item;
    mViewPager.setCurrentItem(item);

    final int tabCount = mTabLayout.getChildCount();
    for (int i = 0; i < tabCount; i++) {
      TabView child = (TabView) mTabLayout.getChildAt(i);
      final boolean isSelected = (i == item);
      child.setSelected(isSelected);
      /*
       * Set text color in case of selected
       */
      if (isSelected) {
        child.setTextColor(Color.rgb(65, 65, 65));
        animateToTab(item);
      } else child.setTextColor(Color.rgb(120, 120, 120));
    }
  }
  private void addTab(int index, CharSequence text, int iconResId) {
    final TabView tabView = new TabView(getContext());
    tabView.mIndex = index;
    tabView.setFocusable(true);
    tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);

    if (iconResId != 0) {
      tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
    }

    mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
  }
  private TabView createTabView(ActionBar.Tab tab, boolean forAdapter) {
    // Workaround for not being able to pass a defStyle on pre-3.0
    final TabView tabView = (TabView) mInflater.inflate(R.layout.abs__action_bar_tab, null);
    tabView.init(this, tab, forAdapter);

    if (forAdapter) {
      tabView.setBackgroundDrawable(null);
      tabView.setLayoutParams(
          new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, mContentHeight));
    } else {
      tabView.setFocusable(true);

      if (mTabClickListener == null) {
        mTabClickListener = new TabClickListener();
      }
      tabView.setOnClickListener(mTabClickListener);
    }
    return tabView;
  }
 @Override
 public void onItemSelected(IcsAdapterView<?> parent, View view, int position, long id) {
   TabView tabView = (TabView) view;
   tabView.getTab().select();
 }