I trying to change the color of the selected tab in PagerTitleStrip, I was able to change the color of the entire strip. But that is not what I wanted.
How to achieve this? Can any one help?
I trying to change the color of the selected tab in PagerTitleStrip, I was able to change the color of the entire strip. But that is not what I wanted.
How to achieve this? Can any one help?
You can do it with PagerTitleStrip too.
Put setOnPageChangeListener for your ViewPager
MyViewPager.setOnPageChangeListener(this);
Then overrride methods onPageScrolled, onPageSelected, onPageScrollStateChanged
we just need to put our code in onPageSelected(int position) method like if you have 5 pages, however beforthat you need - Declare pagerTitleStrip in your main code.
PagerTitleStrip pagerTitleStrip;
And in onCreateMethod
PagerTitleStrip = (PagerTitleStrip) findViewById(R.id.title);
R.id.title is the id of pagerTitleStrip in main_layout
if(position==0){
pagerTitleStrip.setBackgroundColor(0xFF3D0201);
}
if(position==1){
pagerTitleStrip.setBackgroundColor(0xFF013E10);
}
if(position==2){
pagerTitleStrip.setBackgroundColor(0xFF242F52);
}
if(position==3){
pagerTitleStrip.setBackgroundColor(0xFF60611D);
}
if(position==4){
pagerTitleStrip.setBackgroundColor(0xFF5E2E52);
}
If you still want to use PagerTitleStrip
and not PagerTabStrip
all you have to do is below.
tabStrip = (PagerTitleStrip) findViewById(R.id.pager_title_strip);
tabStrip.setBackgroundColor(Color.rgb(240, 240, 240));
tabStrip.getChildAt(1).setPadding(30, 15, 30, 15);
tabStrip.getChildAt(1).setBackgroundResource(R.drawable.background_orange);
This will allow you to set the background color of the middle tab and will not show a tab indicator, like PagerTabStrip
.
Finally figured it out! Considered PagerTabStrip instead of PagerTitleStrip.
Took one day to research on it!