0

Been searching this for a while now and struggling to get anything to work.

I need to change the color of the blue bottom bar to a hex value, I have changed the background color of the tabs, but it didnt change the blue on the TanHost. Is it possible to actually change this? I see youtube made it a nice red, so it must be doable somehow! This is setting up the tabhost:

The tabs are fragments controlled by their own class

// set up the tabhost
         mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
            mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
            mTabHost.addTab(mTabHost.newTabSpec("event").setIndicator("Event Locations",
                    getResources().getDrawable(R.drawable.ic_event_tab)),
                    EventFragment.class, null);
            mTabHost.addTab(mTabHost.newTabSpec("itin").setIndicator("Itinerary",
                    getResources().getDrawable(R.drawable.ic_itin_tab)),
                       ItineraryFragment.class, null);
            mTabHost.addTab(mTabHost.newTabSpec("info").setIndicator("Kendal Info",
                    getResources().getDrawable(R.drawable.ic_info_tab)),
                    KendalInfoFragment.class, null);

            mTabHost.getTabWidget().setBackgroundColor(Color.RED);
Josh Boothe
  • 1,413
  • 4
  • 25
  • 40

1 Answers1

0

Assuming the deprecated library works as it always has, as it should, this is the procedure I have used to colour my tabs. I just set the background in code as follows, as it wasn't direcly accessible in xml:

 TabWidget tabs = (TabWidget)getTabWidget();            
        for (int i = 0; i<tabs.getChildCount(); i++) {
            RelativeLayout tab = (RelativeLayout) tabs.getChildAt(i);
            tab.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.tabindicator));

The tabindicator drawable is as follows:

<?xml version="1.0" encoding="utf-8" ?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--  Non focused states --> 
<item android:state_focused="false" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_unselected" /> 
<item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" /> 
<!--  Focused states  --> 
<item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_focus" /> 
<item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_focus" /> 
 <!--  Pressed  --> 
<item android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/tab_press" /> 
<item android:state_pressed="true" android:drawable="@drawable/tab_press" /> 
</selector>

The drawables were just 9-patch images with the colour, although you may be able to get a similar effect using a standard colour.

OR

Links1 Link2

Community
  • 1
  • 1
ashish.n
  • 1,234
  • 14
  • 30