I need to add a different color for every tabs.
For Eg: like this below image
MainActivity.java:
// Add New Tab
actionBar.addTab(actionBar.newTab().setText("Home")
.setTabListener(tabListener));
actionBar.addTab(actionBar.newTab().setText("News")
.setTabListener(tabListener));
actionBar.addTab(actionBar.newTab().setText("Latest")
.setTabListener(tabListener));
Home.java:
public class Home extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater
.inflate(R.layout.fragment_home, container, false);
((TextView) v.findViewById(R.id.textView)).setText("Home");
return v;
}
}
styles.xml:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
Right now I am created the three tabs.Now I need to add a different color for each tab separately.I need some suggestion regarding to this.Thank you.
You cannot set a different background color on the action bar tabs as they take the color from the action bar itself and thus, they can all be the same color - one color, as the action bar.
If you want to get each tab a different color then you will have to write custom views (Button widgets in a horizontal LinearLayout with view pager) to simulate the behavior of tabs.
yes,finally I done it.
MainActivity.java:
gradient_shape.xml:
Output:
Hope it will be helpful.