4

I'm creating a SlidingPageLayout but it does not have icons. I'm setting a viewPager for this slidingpageLayout. The viewpager has a PagerAdapter and PagerAdapter sets the title of the page. I want to set an icon instead of a text. Reference question: Android SlidingTabLayout with icons

Community
  • 1
  • 1
user1159517
  • 5,390
  • 8
  • 30
  • 47

1 Answers1

0

would 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;
            }
        }
    });
zoruc
  • 819
  • 7
  • 13