Android ViewPager with icons

I am creating a SlidingPageLayout, but it has no icons. I set the viewPager for this moving page. The Viewpager has a PagerAdapter, and the PagerAdapter sets the page title. I want to set an icon instead of text. Help question: Android SlidingTabLayout with icons

+4
source share
1 answer

there will be something like this work for you

Actionbar mActionbar = getActionbar();
mActionBar.setTitle("");
mActionBar.setIcon(getResources().getDrawable(R.drawable.icon1))

mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @SuppressLint("NewApi")
        @Override
        public void onPageSelected(int position) {
            mViewPager.setCurrentItem(position);
            switch (position) {
            case 0:
                mActionBar.setIcon(getResources().getDrawable(R.drawable.icon1))
                break;
            case 1:
                mActionBar.setIcon(getResources().getDrawable(R.drawable.icon2))
                break;
            default:
                mActionBar.setIcon(getResources().getDrawable(R.drawable.icon1))
                break;
            }
        }
    });
0
source

Source: https://habr.com/ru/post/1538947/


All Articles