如何设置标签视图指示灯背景颜色的Andr​​oid [英] How to set Tab View Indicator background color in Android

查看:131
本文介绍了如何设置标签视图指示灯背景颜色的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何改变颜色上点击选项卡中的主机。我可以改变形象,但颜色是不会改变的。

 公共类MainActivity延伸活动{
    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);

        的setContentView(R.layout.activity_main);

        TabHost tabHost =(TabHost)findViewById(R.id.tabHost);
        tabHost.setup();

        则tabspec SPEC1 = tabHost.newTabSpec(标签1);
        spec1.setContent(R.id.tab1);`输入code here`
        spec1.setIndicator(标签1,getResources()getDrawable(setBackgroundColor(Color.RED))。

        则tabspec spec2 = tabHost.newTabSpec(标签2);
        spec2.setIndicator(标签2,getResources()getDrawable(setBackgroundColor(Color.GREAN))。
        spec2.setContent(R.id.tab2);

        则tabspec spec3 = tabHost.newTabSpec(标签3);
        spec3.setIndicator(标签3,getResources()getDrawable(setBackgroundColor(Color.BLACK))。
        spec3.setContent(R.id.tab3);

        tabHost.addTab(SPEC1);
        tabHost.addTab(spec2);
        tabHost.addTab(spec3);
    }
}
 

解决方案

 公共类MainActivity延伸活动{
    @覆盖
    保护无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);

        的setContentView(R.layout.activity_main);

        TabHost tabHost =(TabHost)findViewById(R.id.tabHost);
        tabHost.setup();

        则tabspec SPEC1 = tabHost.newTabSpec(标签1);
        spec1.setContent(R.id.tab1);`输入code here`
        spec1.setIndicator(标签1,getResources()getDrawable(setBackgroundColor(view.Color.RED))。

        则tabspec spec2 = tabHost.newTabSpec(标签2);
        spec2.setIndicator(标签2,getResources()getDrawable(setBackgroundColor(view.Color.GREAN))。
        spec2.setContent(R.id.tab2);

        则tabspec spec3 = tabHost.newTabSpec(标签3);
        spec3.setIndicator(标签3,getResources()getDrawable(setBackgroundColor(view.Color.BLACK))。
        spec3.setContent(R.id.tab3);

        tabHost.addTab(SPEC1);
        tabHost.addTab(spec2);
        tabHost.addTab(spec3);
    }
}
 

How to Change color on click tab Host. i can change image but color are not change.

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
        tabHost.setup();

        TabSpec spec1=tabHost.newTabSpec("Tab 1");
        spec1.setContent(R.id.tab1);`enter code here`
        spec1.setIndicator("Tab 1", getResources().getDrawable(setBackgroundColor(Color.RED));

        TabSpec spec2=tabHost.newTabSpec("Tab 2");
        spec2.setIndicator("Tab 2", getResources().getDrawable(setBackgroundColor(Color.GREAN));
        spec2.setContent(R.id.tab2);

        TabSpec spec3=tabHost.newTabSpec("Tab 3");
        spec3.setIndicator("Tab 3", getResources().getDrawable(setBackgroundColor(Color.BLACK));
        spec3.setContent(R.id.tab3);

        tabHost.addTab(spec1);
        tabHost.addTab(spec2);
        tabHost.addTab(spec3);
    }
}

解决方案

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
        tabHost.setup();

        TabSpec spec1=tabHost.newTabSpec("Tab 1");
        spec1.setContent(R.id.tab1);`enter code here`
        spec1.setIndicator("Tab 1", getResources().getDrawable(setBackgroundColor(view.Color.RED));

        TabSpec spec2=tabHost.newTabSpec("Tab 2");
        spec2.setIndicator("Tab 2", getResources().getDrawable(setBackgroundColor(view.Color.GREAN));
        spec2.setContent(R.id.tab2);

        TabSpec spec3=tabHost.newTabSpec("Tab 3");
        spec3.setIndicator("Tab 3", getResources().getDrawable(setBackgroundColor(view.Color.BLACK));
        spec3.setContent(R.id.tab3);

        tabHost.addTab(spec1);
        tabHost.addTab(spec2);
        tabHost.addTab(spec3);
    }
}

这篇关于如何设置标签视图指示灯背景颜色的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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