改變android 選項卡的背景色

來源:互聯網
上載者:User

看如下代碼:

  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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.