改变android 选项卡的背景色

看如下代码:

  mTabHost = (TabHost) findViewById(R.id.tabhost);
        mTabHost.setup();
        final TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs);
        LayoutInflater inflater_tab1 = LayoutInflater.from(this);
        inflater_tab1.inflate(R.layout.mobile_phone_cashier_tab1, mTabHost
                .getTabContentView());
        inflater_tab1.inflate(R.layout.mobile_phone_cashier_tab2, mTabHost
                .getTabContentView());
        inflater_tab1.inflate(R.layout.mobile_phone_cashier_tab3, mTabHost
                .getTabContentView());
        // inflater_tab1.inflate(R.layout.mobile_phone_cashier_tab4, mTabHost
        // .getTabContentView());
        // inflater_tab1.inflate(R.layout.mobile_phone_cashier_tab5, mTabHost
        // .getTabContentView());
        // inflater_tab1.inflate(R.layout.mobile_phone_cashier_tab1_request,
        // mTabHost
        // .getTabContentView());
        mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator(
                getString(R.string.sy)).setContent(R.id.FrameLayout01));
        mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator(
                getString(R.string.cd)).setContent(R.id.FrameLayout02));
        mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator(
                getString(R.string.jyjl)).setContent(R.id.FrameLayout03));
        // mTabHost.addTab(mTabHost.newTabSpec("tab4").setIndicator(
        // getString(R.string.yye)).setContent(R.id.FrameLayout04));
        // mTabHost.addTab(mTabHost.newTabSpec("tab5").setIndicator(
        // getString(R.string.jyjl)).setContent(R.id.FrameLayout05));
        tabWidget.setBackgroundResource(R.drawable.tab_bg);
        Field mBottomLeftStrip;
        Field mBottomRightStrip;
        for (int i = 0; i < tabWidget.getChildCount(); i++) {
            final TextView tv = (TextView) tabWidget.getChildAt(i)
                    .findViewById(android.R.id.title);
            tabWidget.getChildAt(i).getLayoutParams().height = 40;
            if (i == 0) {
                tabWidget.getChildAt(i).setBackgroundResource(
                        R.drawable.tab_kuang);//设置背景
                tv.setTextColor(Color.rgb(202, 151, 0));
            } else {
                tabWidget.getChildAt(i)
                        .setBackgroundResource(R.drawable.tab_bg);
                tv.setTextColor(Color.WHITE);
                tabWidget.getChildAt(i).setClickable(false);
            }
            tv.setTextSize(15);
            tv.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
        } 

原理就是更改系统自带的tabwidget

你可能感兴趣的:(android)