Java Android TabHost更改底部栏的颜色
搜索这个已经有一段时间了,努力让任何东西都能正常工作 我需要将蓝色底部栏的颜色更改为十六进制值,我已经更改了选项卡的背景颜色,但它没有更改TanHost上的蓝色。真的有可能改变这一点吗?我看到youtube把它做成了一个漂亮的红色,所以它一定是可行的!这是设置选项卡主机: 选项卡是由它们自己的类控制的片段Java Android TabHost更改底部栏的颜色,java,android,Java,Android,搜索这个已经有一段时间了,努力让任何东西都能正常工作 我需要将蓝色底部栏的颜色更改为十六进制值,我已经更改了选项卡的背景颜色,但它没有更改TanHost上的蓝色。真的有可能改变这一点吗?我看到youtube把它做成了一个漂亮的红色,所以它一定是可行的!这是设置选项卡主机: 选项卡是由它们自己的类控制的片段 // set up the tabhost mTabHost = (FragmentTabHost)findViewById(android.R.id.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);
假设不推荐使用的库一如既往地工作,这是我用来给选项卡上色的过程。我只是在代码中设置了背景,如下所示,因为它在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));
TabWidget tabs=(TabWidget)getTabWidget();
对于(int i=0;i
<?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>