i have created the new project in eclipse file->new->other->android application project
in this navigation type i gave action bar tab with view pager, i eclipse automatically created with actionbar with tabs, what i need is want to change the actionbar bg and tab bg and tab indicator bg,i have changed actionbar background color no problem in that, but i have no idea about changing the actionbar tab background color and that default tab indicator blue color?
Here is my code.
public class MainActivity extends ActionBarActivity implements
ActionBar.TabListener {
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set up the action bar.
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
String text = "<font color=#3e4093>Save</font> <font color=#ed3338>life</font>";
mTitleTextView.setText(Html.fromHtml(text));
actionBar.setCustomView(mCustomView);
actionBar.setDisplayShowCustomEnabled(true);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setOffscreenPageLimit(2);
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
actionBar.addTab(actionBar.newTab()
.setIcon(mSectionsPagerAdapter.getIcon(i))
.setTabListener(this));
}
}
@Override
public void onTabSelected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
public Drawable getIcon(int position) {
switch (position) {
case 0:
return getResources().getDrawable(R.drawable.ic_home);
case 1:
return getResources().getDrawable(R.drawable.ic_info);
case 2:
return getResources().getDrawable(R.drawable.ic_more);
}
return null;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new firstTab();
case 1:
return new secondTab();
case 2:
return new ThirdTab();
}
return null;
}
@Override
public int getCount() {
// Show 3 total pages.
return 3;
}
}}