Code example for ViewPager

Methods: getContext, onFinishInflate, setBackgroundDrawable

0
        setIndicator(0, 0); 
    } 
     
    @Override 
    protected void onFinishInflate() { 
        super.onFinishInflate(); 
         
        // Available after 1.6, sets the shortcut pages background with the device's wallpaper. 
        Drawable wallpaper = Wallpaper.get(getContext());
        if(wallpaper != null)
            setBackgroundDrawable(wallpaper);
    } 
     
    @Override 
    protected void onPageScrolled(int position, float offset, int offsetPixels) {
        super.onPageScrolled(position, offset, offsetPixels);
        setIndicator(position, offset);
    } 
 
    private void setIndicator(int position, float offset) {
        int pages = Math.max(getChildCount(), pageCount);