Android TabHost更改底栏的颜色

时间:2013-06-21 11:03:15

标签: java android

现在已经搜索了一段时间,并努力让任何事情发挥作用。

我需要将蓝色底栏的颜色更改为十六进制值,我已经更改了选项卡的背景颜色,但它没有改变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);

1 个答案:

答案 0 :(得分:0)

假设已弃用的库按原样运行,就像它应该的那样,这是我用来为我的选项卡着色的过程。我只是在代码中设置背景如下,因为它在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));

tabindicator drawable如下:

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