| | |
| | | import android.content.Context; |
| | | import android.content.res.Resources; |
| | | import android.graphics.Color; |
| | | import android.graphics.Typeface; |
| | | import android.support.v4.view.PagerAdapter; |
| | | import android.support.v4.view.ViewPager; |
| | | import android.support.v4.view.ViewPager.OnPageChangeListener; |
| | | import android.util.AttributeSet; |
| | | import android.util.Log; |
| | | import android.util.TypedValue; |
| | | import android.view.Gravity; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.HorizontalScrollView; |
| | |
| | | |
| | | private int mMaxTabWidth; |
| | | private int mSelectedTabIndex; |
| | | private int textColor; |
| | | private int highLightTextColor; |
| | | |
| | | private OnTabReselectedListener mTabReselectedListener; |
| | | |
| | | public MainTabPageIndicator(Context context) { |
| | | this(context, null); |
| | | } |
| | | |
| | | public void setTextColor(int textColor, int highLightTextColor) { |
| | | this.textColor = textColor; |
| | | this.highLightTextColor = highLightTextColor; |
| | | } |
| | | |
| | | |
| | | public MainTabPageIndicator(Context context, AttributeSet attrs) { |
| | | super(context, attrs); |
| | |
| | | removeCallbacks(mTabSelector); |
| | | } |
| | | for (int i = 0; i < mTabLayout.getChildCount(); i++) { |
| | | ((TextView) mTabLayout.getChildAt(i)).setTextSize( |
| | | TypedValue.COMPLEX_UNIT_SP, 15); |
| | | ((TextView) mTabLayout.getChildAt(i)).setTextColor(Color.parseColor("#999999")); |
| | | ((TextView) mTabLayout.getChildAt(i)).setTextSize(15); |
| | | ((TextView) mTabLayout.getChildAt(i)).setTextColor(textColor); |
| | | ((TextView) mTabLayout.getChildAt(i)).setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); |
| | | } |
| | | ((TextView) tabView).setTextColor(Color.WHITE); |
| | | ((TextView) tabView).setTextSize( |
| | | TypedValue.COMPLEX_UNIT_SP, 20); |
| | | ((TextView) tabView).setTextColor(highLightTextColor); |
| | | ((TextView) tabView).setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); |
| | | ((TextView) tabView).setTextSize(20); |
| | | // ((TextView) tabView).setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT,WRAP_CONTENT)); |
| | | mTabSelector = new Runnable() { |
| | | public void run() { |
| | |
| | | @SuppressLint("ResourceAsColor") |
| | | private void addTab(int index, CharSequence text, int iconResId) { |
| | | final TabView tabView = new TabView(getContext()); |
| | | tabView.setPadding(0, 0, 0, 0); |
| | | tabView.mIndex = index; |
| | | tabView.setFocusable(true); |
| | | tabView.setOnClickListener(mTabClickListener); |
| | | tabView.setText(text); |
| | | tabView.setTextColor(R.color.black1); |
| | | |
| | | tabView.setBackgroundResource(R.drawable.found__tab_indicator); |
| | | if (textColor > 0) { |
| | | tabView.setTextColor(textColor); |
| | | } else { |
| | | tabView.setTextColor(R.color.black1); |
| | | } |
| | | tabView.setBackgroundColor(Color.TRANSPARENT); |
| | | |
| | | if (iconResId != 0) { |
| | | tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0); |
| | | } |
| | | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(WRAP_CONTENT, |
| | | MATCH_PARENT, 1); |
| | | WRAP_CONTENT, 1); |
| | | mTabLayout.addView(tabView, params); |
| | | MarginLayoutParams marginLayoutParams = (MarginLayoutParams) tabView.getLayoutParams(); |
| | | if (index == 0) |
| | | marginLayoutParams.leftMargin = DimenUtils.dip2px(getContext(), 10); |
| | | else |
| | | marginLayoutParams.leftMargin = DimenUtils.dip2px(getContext(), 21); |
| | | else { |
| | | marginLayoutParams.leftMargin = DimenUtils.dip2px(getContext(), 13); |
| | | } |
| | | |
| | | if (index == mTabLayout.getChildCount() - 1) { |
| | | marginLayoutParams.rightMargin = DimenUtils.dip2px(getContext(), 10); |
| | | } |
| | | } |
| | | |
| | | @Override |