Reputation: 103
I'm doing SwipeTab android project. (picture below)
So how can I replace Tab1,2,3 by another icon? And how can I change color or decorate action bar? My code here:
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionbar.addTab(actionbar.newTab().setText("Tab1").setTabListener(this));
actionbar.addTab(actionbar.newTab().setText("Tab2").setTabListener(this));
actionbar.addTab(actionbar.newTab().setText("Tab3").setTabListener(this));
viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
Upvotes: 0
Views: 67
Reputation: 3687
You can setup icon as follows ,
actionBar.addTab(
actionBar.newTab()
.setText(your text)
.setIcon(getResources().getDrawable(<your icon>))
.setTabListener(this));
And you can change the color by as follows, Create a color xml including defined color and put that into drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<color xmlns:android="http://schemas.android.com/apk/res/android"
android:color="color code">
</color>
then - for action bar only
actionBar.setBackgroundDrawable(getResources().getDrawable(file name));
for tabs only
actionBar.setStackedBackgroundDrawable(getResources().getDrawable(file name));
Upvotes: 0
Reputation: 12378
Add icon in this manner, using setIcon
method
actionBar.addTab( actionBar.newTab()
.setText(null)
.setIcon(R.drawable.activity)
.setTabListener(this));
Upvotes: 1