Android view pager with page indicator

后端 未结 7 1531
终归单人心
终归单人心 2020-12-07 19:23

I need to get page indicator in the view pager file with images. Here is my code.

public class IndicatorActivity extends Activity {


 /** Called when the ac         


        
7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 19:55

    You Can create a Linear layout containing an array of TextView (mDots). To represent the textView as Dots provide this HTML source in your code . refer my code . I got this information from Youtube Channel TVAC Studio . here the code : `

        addDotsIndicator(0);
        viewPager.addOnPageChangeListener(viewListener);
    }
    
    public void addDotsIndicator(int position)
    {
            mDots = new TextView[5];
            mDotLayout.removeAllViews();
    
            for (int i = 0; i0)
            {
                mDots[position].setTextColor(getResources().getColor(R.color.orange));
            }
    }
    
    ViewPager.OnPageChangeListener viewListener = new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int 
       positionOffsetPixels) {
    
        }
    
        @Override
        public void onPageSelected(int position) {
    
            addDotsIndicator(position);
        }
    
        @Override
        public void onPageScrollStateChanged(int state) {
    
        }
    };`
    

提交回复
热议问题