无法改变android中Tabhost的背景颜色

时间:2015-05-05 06:32:53

标签: android android-tabhost

最近,我制作了一个使用Tabhost的简单应用程序。 但是,我无法为其设置颜色。我在下面设置了示例代码。我如何能够为当前代码添加颜色?如果我能得到小费或帮助,那将是一个很大的帮助。

   Resources res = getResources();
        TabHost tabHost = getTabHost();
        TabSpec spec;
        Intent intent;

        //tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#C0392B"));


        intent = new Intent().setClass(this, SecondActivity.class);

        spec = tabHost.newTabSpec("Second Activity").setIndicator(res.getString(R.string.act_second), res.getDrawable(R.drawable.ic_tab)).setContent(intent);
        tabHost.addTab(spec);

1 个答案:

答案 0 :(得分:1)

我在tabHost方法中设置了tabChanged的颜色,如:

for( int i=0;i<mTabHost.getTabWidget().getChildCount();i++)
    {
        mTabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#7392B5"));
    }
mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#4E4E9C"));