简体   繁体   中英

actionbar tab indicator is NOT applying custom styles

I have this issue with a viewpager with actionbar tabs, basically I'm not able to apply any of my custom styles to the tabs, this is what I have

在此处输入图片说明

ok so this is using the default tabbed activity that comes with android studio 1.1 here is a list of characteristics I'm have

  • the default template use the appCompat v4 viewpager with fragments
  • I have a custom style generated from here http://jgilfelt.github.io/android-actionbarstylegenerator/ , I know is deprecated but it still should work for now
  • below is the code part of the code of my activity
  • min sdk is set to 21
  • is using buildtools 21.2.1
  • and support library v4 revision 22.0

MainActivity

    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);

        final ActionBar actionBar = getSupportActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        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()

activity_main.xml

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:id="@+id/pager"
    android:layout_width="match_parent" android:layout_height="match_parent"
    tools:context=".MainActivity" />

I have my custom styles inside the styles.xml and and I have applied them in the manifest

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.CustomTheme" >

This is a small part of my styles that I know is trying to change to a red color indicator

<style name="ActionBarTabStyle.Aeroman" parent="@style/Widget.AppCompat.ActionBar.TabView">
        <item name="android:background">@drawable/tab_indicator_ab_customTheme</item>
    </style>

which is using a red indicator color

All looks good to me but as u can see in the screenshot is juts ignoring those styles, I know some of the styles in the styles files are been applied, because for example I have a Theme.AppCompat.Light.DarkActionBar as the parent and if I change it to Theme.AppCompat.Light, the actionBar turns gray, so is working that part, the weird thing for me is that the tab indicator is green which I think it should be blue right? and is very thin by default.

I tested in a genymotion emulator using Nexus 4 with API 16 and in a real device using Nexus 5 with android 5.0.1

Please help understand this, I pulling my hair here, thanks for any help

使用不带android:前缀的appcompat属性名称,即:

        <item name="actionBarTabStyle">@style/ActionBarTabStyle.YourProject</item>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM