更改特定标签的背景颜色android的选项卡刷卡 [英] Change background color of a specific tab in android tabs swipe

查看:138
本文介绍了更改特定标签的背景颜色android的选项卡刷卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的我的主要活动的onCreate

This is my onCreate of my main activity

private ViewPager viewPager;
    private TabsPagerAdapter mAdapter;
    private ActionBar actionBar;
    private TabHost tabHost;
    // Tab titles
    private String[] tabs = { "1", "2", "3" };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        // Initialization
        viewPager = (ViewPager) findViewById(R.id.pager);
        actionBar = getActionBar();
        mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
        //actionBar.setStackedBackgroundDrawable(new ColorDrawable(0xFFFF0000));
        tabHost = (TabHost) findViewById(android.R.id.tabhost);
        Log.d("miau", String.valueOf(tabHost));


        viewPager.setAdapter(mAdapter);
        actionBar.setHomeButtonEnabled(false);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        // Adding Tabs
        for (String tab_name : tabs) {
            actionBar.addTab(actionBar.newTab().setText(tab_name)
                    .setTabListener(this));
        }

我需要每个标签有不同的颜色。任何指针?先谢谢了。

I need that every tab have a different color. Any pointer? thanks in advance.

推荐答案

只是采取特定标签的ImageView的在相应的XML。然后给该图像显示宽度和高度MatchParent。并设置该ImageView的的backgroung颜色。

Just take the ImageView for the particular Tab in the corresponding xml. And then give that image view Width and Height "MatchParent". And set the backgroung color for that Imageview.

这篇关于更改特定标签的背景颜色android的选项卡刷卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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