如何更改android默认的eclipse actionbar选项卡背景?

如何更改android默认的eclipse actionbar选项卡背景?,android,tabs,android-actionbar,Android,Tabs,Android Actionbar,我已经在eclipse文件->新建->其他->android应用程序项目中创建了新项目 在这个导航类型中,我给了带有视图寻呼机的操作栏选项卡,我用带有选项卡的操作栏自动创建了eclipse,我需要的是更改操作栏bg和选项卡bg以及选项卡指示器bg,我已经更改了操作栏背景色,没有问题,但我不知道如何更改actionbar选项卡的背景色和默认选项卡指示器的蓝色 这是我的密码 public class MainActivity extends ActionBarActivity implements

我已经在eclipse文件->新建->其他->android应用程序项目中创建了新项目

在这个导航类型中,我给了带有视图寻呼机的操作栏选项卡,我用带有选项卡的操作栏自动创建了eclipse,我需要的是更改操作栏bg和选项卡bg以及选项卡指示器bg,我已经更改了操作栏背景色,没有问题,但我不知道如何更改actionbar选项卡的背景色和默认选项卡指示器的蓝色

这是我的密码

public class MainActivity extends ActionBarActivity implements
    ActionBar.TabListener {

SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;

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

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowTitleEnabled(false);
    LayoutInflater mInflater = LayoutInflater.from(this);

    View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
    TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
    String text = "<font color=#3e4093>Save</font> <font color=#ed3338>life</font>";
    mTitleTextView.setText(Html.fromHtml(text));
    actionBar.setCustomView(mCustomView);
    actionBar.setDisplayShowCustomEnabled(true);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
                @Override
                public void onPageSelected(int position) {
                    actionBar.setSelectedNavigationItem(position);
                }
            });
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(actionBar.newTab()
                .setIcon(mSectionsPagerAdapter.getIcon(i))
                .setTabListener(this));

    }
}

@Override
public void onTabSelected(ActionBar.Tab tab,
        FragmentTransaction fragmentTransaction) {
    mViewPager.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(ActionBar.Tab tab,
        FragmentTransaction fragmentTransaction) {
}

@Override
public void onTabReselected(ActionBar.Tab tab,
        FragmentTransaction fragmentTransaction) {
}

/**
 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
 * one of the sections/tabs/pages.
 */
public class SectionsPagerAdapter extends FragmentPagerAdapter {

    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public Drawable getIcon(int position) {

        switch (position) {
        case 0:
            return getResources().getDrawable(R.drawable.ic_home);
        case 1:
            return getResources().getDrawable(R.drawable.ic_info);
        case 2:
            return getResources().getDrawable(R.drawable.ic_more);
        }
        return null;
    }

    @Override
    public Fragment getItem(int position) {
        switch (position) {
        case 0:
            return new firstTab();
        case 1:
            return new secondTab();
        case 2:
            return new ThirdTab();
        }
        return null;
    }

    @Override
    public int getCount() {
        // Show 3 total pages.
        return 3;
    }
}}
public类MainActivity扩展了ActionBarActivity实现
ActionBar.TabListener{
分段SPAGERADAPTER mSectionsPagerAdapter;
ViewPager mViewPager;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//设置操作栏。
最终ActionBar ActionBar=getSupportActionBar();
actionBar.setNavigationMode(actionBar.NAVIGATION\u MODE\u选项卡);
actionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater=LayoutInflater.from(this);
视图mCustomView=mInflater.flate(R.layout.custom\u actionbar,null);
TextView mTitleTextView=(TextView)mCustomView.findViewById(R.id.title_text);
String text=“拯救生命”;
mTitleTextView.setText(Html.fromHtml(text));
actionBar.setCustomView(mCustomView);
actionBar.setDisplayShowCustomEnabled(true);
//创建适配器,该适配器将为这三个函数中的每一个返回一个片段
//活动的主要部分。
mSectionsPagerAdapter=newsectionspageradapter(getSupportFragmentManager());
//使用分区适配器设置ViewPager。
mViewPager=(ViewPager)findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setOffscreenPageLimit(2);
mViewPager.setOnPageChangeListener(新的ViewPager.SimpleOnPageChangeListener(){
@凌驾
已选择页面上的公共无效(内部位置){
actionBar.setSelectedNavigationItem(位置);
}
});
对于(int i=0;i
将此作为参考

您的样式文件应该如下所示

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
         <!-- All customizations that are NOT specific to a particular API-level can go here. -->
         <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">#1ADEDB </item>
    </style>

</resources>

@样式/MyActionBar
#1ADEDB
更改选项卡背景色

这个工具似乎很适合为动作栏生成样式


我使用了此链接,并使用此链接更改了actionbar选项卡的背景色,非常有用,谢谢@BlaShadow


更改选项卡背景颜色

此样式适用于以上版本11,且不更改actionbar选项卡背景颜色