hackware1993 / MagicIndicator

A powerful, customizable and extensible ViewPager indicator framework. As the best alternative of ViewPagerIndicator, TabLayout and PagerSlidingTabStrip —— 强大、可定制、易扩展的 ViewPager 指示器框架。是ViewPagerIndicator、TabLayout、PagerSlidingTabStrip的最佳替代品。支持角标,更支持在非ViewPager场景下使用(使用hide()、show()切换Fragment或使用setVisibility切换FrameLayout里的View等),http://www.jianshu.com/p/f3022211821c
9.68k stars 1.54k forks source link

如何设置TitleView的背景色,直接设置后,指示器的颜色会被遮住 #296

Open liquor2020 opened 9 months ago

liquor2020 commented 9 months ago
commonNavigator.setAdapter(new CommonNavigatorAdapter() {

       @Override
        public int getCount() {
            return null == titleList ? 0 : titleList.size();
        }

        @Override
        public IPagerTitleView getTitleView(Context context, final int index) {
            SimplePagerTitleView titleView = new SimplePagerTitleView(context);
            titleView.setText(titleList.get(index));
            titleView.setTextSize(14);
            titleView.setNormalColor(ContextCompat.getColor(GenerateResultActivity.this, R.color._666666));
            titleView.setSelectedColor(ContextCompat.getColor(GenerateResultActivity.this, R.color.white));
            // 设置背景色
            titleView.setBackground(ContextCompat.getDrawable(GenerateResultActivity.this, R.drawable.bg_generate));
            titleView.setOnClickListener(v -> mBinding.viewPager.setCurrentItem(index));
            return titleView;
        }

        @Override
        public IPagerIndicator getIndicator(Context context) {
            LinePagerIndicator indicator = new LinePagerIndicator(context);
            indicator.setLineHeight(ConvertUtils.dp2px(34));
            indicator.setRoundRadius(ConvertUtils.dp2px(8));
            indicator.setColors(ContextCompat.getColor(GenerateResultActivity.this, R.color._F95A23));
            return indicator;
        }
    });