是否有可能改变所选标签的颜色android的?有可能、所选、颜色、标签

2023-09-13 23:46:40 作者:狗绕道@

我有我的标签控件两个选项卡,我想申请两个不同颜色的两个tabs.am到处搜寻,主要是所有的颜色都是一样的,而应用的标签。

更新

第一个标签:当选择红色

第二个标签:当选择了蓝色

下面我code

  tabHost =(TabHost)findViewById(android.R.id.tabhost);
    则tabspec firstTabSpec = tabHost.newTabSpec(TID1); //这些都是红色
    则tabspec secondTabSpec = tabHost.newTabSpec(TID1); //这些颜色是蓝色
    firstTabSpec.setIndicator(销售信息,getResources()getDrawable(R.drawable.sales)。);
    意图photosIntent =新的意图(这一点,的A.class);
    firstTabSpec.setContent(photosIntent);
    secondTabSpec.setIndicator(服务信息,getResources()getDrawable(R.drawable.services)。);
    意图photosIntent1 =新的意图(这一点,b.class);
    secondTabSpec.setContent(photosIntent1);
    tabHost.addTab(firstTabSpec);
    tabHost.addTab(secondTabSpec);
 

解决方案

试试这个:

  ...的onCreate(){

     ...
     tabHost.setOnTabChangedListener(新OnTabChangeListener(){

    @覆盖
    公共无效onTabChanged(字符串为arg0){

        setTabColor(tabHost);
    }
     });
     setTabColor(tabHost);
...
}

//更改选项卡的Backgournd颜色
公共无效setTabColor(TabHost tabhost){

    的for(int i = 0; I< tabhost.getTabWidget()getChildCount();我++)
        。tabhost.getTabWidget()getChildAt(ⅰ).setBackgroundColor(COLOR_CYAN); //未选

    如果(tabhost.getCurrentTab()== 0)
           。tabhost.getTabWidget()getChildAt(tabhost.getCurrentTab())setBackgroundColor(COLOR_RED)。 //选择第一选项卡
    其他
           。tabhost.getTabWidget()getChildAt(tabhost.getCurrentTab())setBackgroundColor(COLOR_BLUE)。 //选择第二个选项卡
}
 
excel如何自动标记颜色

Hi i have two tabs in my tab widget,i want to apply the two different color for two tabs.am searching everywhere,mostly all colors are same while applying the tab.

update

first tab when selected red color

second tab when selected blue color

Here my code

tabHost = (TabHost)findViewById(android.R.id.tabhost);
    TabSpec firstTabSpec = tabHost.newTabSpec("tid1");//these are color red
    TabSpec secondTabSpec = tabHost.newTabSpec("tid1");//these color blue
    firstTabSpec.setIndicator("Sales Info",getResources().getDrawable(R.drawable.sales));
    Intent photosIntent = new Intent(this, a.class);
    firstTabSpec.setContent(photosIntent);
    secondTabSpec.setIndicator("Service Info",getResources().getDrawable(R.drawable.services));
    Intent photosIntent1 = new Intent(this, b.class);
    secondTabSpec.setContent(photosIntent1);
    tabHost.addTab(firstTabSpec);
    tabHost.addTab(secondTabSpec);

解决方案

Try this:

...onCreate(){

     ...
     tabHost.setOnTabChangedListener(new OnTabChangeListener() {

    @Override
    public void onTabChanged(String arg0) {

        setTabColor(tabHost);
    }
     });
     setTabColor(tabHost);
...
}

//Change The Backgournd Color of Tabs
public void setTabColor(TabHost tabhost) {

    for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
        tabhost.getTabWidget().getChildAt(i).setBackgroundColor(COLOR_CYAN); //unselected

    if(tabhost.getCurrentTab()==0)
           tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_RED); //1st tab selected
    else
           tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_BLUE); //2nd tab selected
}