2013-06-21 79 views
0

一直在搜索这一段时间,并努力获得任何工作。Android TabHost改变底部条的颜色

我需要将蓝色底部栏的颜色更改为十六进制值,我已更改了选项卡的背景颜色,但没有更改TanHost上的蓝色。有没有可能改变这一点?我看到youtube使它成为一个很好的红色,所以它必须以某种方式可行!这是建立tabhost:

的选项卡片段通过自己的阶级

// 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); 

回答

0

假设过时的库工作,因为它总是有,因为它应该控制的,这是我已经习惯了颜色的程序我的标签。我刚才设置的背景中的代码如下,因为它是不是在XML direcly访问:

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)); 

的tabindicator绘制如下:

<?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> 

的可绘制只是9块图像与颜色,虽然你可能能够使用标准颜色获得类似的效果。

OR

Links1 Link2