2

私は自分のアプリケーションで tabHost を使用しており、要件は、任意のタブが選択されたときにタブ インジケーターの色を変更する必要があることです。この例を参照しました Android でタブ ビュー インジケーターの背景色を設定する方法を参照しましたが、理解できませんでした ここに私のコードがあります:

    TabHost tabHost = getTabHost();  // The activity TabHost

            TabHost.TabSpec spec;  // Reusable TabSpec for each tab
            Intent intent;  // Reusable Intent for each tab

            // Create an Intent to launch an Activity for the tab (to be reused)
            intent = new Intent().setClass(this, HomePage.class);
            // Initialize a TabSpec for each tab and add it to the TabHost
            spec = tabHost.newTabSpec("tabOne");  
            spec.setContent(intent);  
            spec.setIndicator("Home");  
            tabHost.addTab(spec);
            // Squash the tab a little bit horizontally
            tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 40;
            tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 50;

            // Bump the text size upll.getChildAt(0);

            // Do the same for the other tabs
            intent = new Intent().setClass(this, MoteIt.class);
            spec = tabHost.newTabSpec("tabTwo");  
            spec.setContent(intent);  
            spec.setIndicator("moteit");

            tabHost.addTab(spec);
            tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 40;


            intent = new Intent().setClass(this, Lifeline.class);
            spec = tabHost.newTabSpec("tabThree");  
            spec.setContent(intent);  
            spec.setIndicator("lifeline");
            tabHost.addTab(spec);
            tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 40;


            intent = new Intent().setClass(this, CircleOfTrust.class);
            spec = tabHost.newTabSpec("tabfour");  
            spec.setContent(intent);  
            spec.setIndicator("Cot");
            tabHost.addTab(spec);
            tabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 40;

            intent = new Intent().setClass(this, Search.class);
            spec = tabHost.newTabSpec("tabFive");  
            spec.setContent(intent);  
            spec.setIndicator("Search");
            tabHost.addTab(spec);
            tabHost.getTabWidget().getChildAt(4).getLayoutParams().height = 40;
            tabHost.getTabWidget().setStripEnabled(true);
            tabHost.setCurrentTab(0);

前もって感謝します

4

3 に答える 3

0

これを試して

    PagerTabStrip tabStrip = (PagerTabStrip) findViewById(R.id.pager_title_strip);
    tabStrip.setBackgroundColor(Color.rgb(240, 240, 240));

それが役に立てば幸い。

于 2013-10-11T07:29:54.157 に答える
-1

レイアウト xml で色を設定できます。

android:background = "@color/....";
于 2013-10-11T07:32:06.663 に答える