是否有可能改变所选标签的颜色android的? [英] Is it possible to change the color of selected Tab in android?

查看:167
本文介绍了是否有可能改变所选标签的颜色android的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的标签控件两个选项卡,我想申请两个不同颜色的两个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)。 //选择第二个选项卡
}
 

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
}

这篇关于是否有可能改变所选标签的颜色android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆