Android ActionBar样式未应用

时间:2015-06-09 07:45:42

标签: android android-actionbar android-styles

我一直在尝试更改操作栏中标签和菜单的文字颜色。我在这里关注了一些已回答的问题并查看了Android开发者网站。我已对代码进行了更改,但我的style.xml文件中的主题未应用。

我的清单中指定的minSdkVersion是19,我在棒棒糖设备上运行。

styles.xml

<style name="MyActionBarTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item>
    <item name="android:actionMenuTextColor">@color/green</item>
</style>

<style name="MyActionBar" parent="android:style/Widget.Holo.ActionBar">
    <item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
</style>

<style name="MyActionBarTitleText" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/white</item>
</style>

<style name="MyActionBarTabText" parent="android:style/Widget.Holo.ActionBar.TabText">
    <item name="android:textColor">@color/white</item>
</style>

的AndroidManifest.xml

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Holo.Light">

MainActivity.java

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();

    actionBar.setHomeButtonEnabled(false);

    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab()
                        .setText(mAppSectionsPagerAdapter.getPageTitle(i))
                        .setTabListener(this));
    }       

与往常一样,非常感谢任何帮助:)

1 个答案:

答案 0 :(得分:0)

AndroidManifest.xml

中使用此代码
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/MyActionBarTheme >

并将此代码用于 Styles.xml

<resources>
    <style name="MyActionBarTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
        <item name="android:actionBarTabTextStyle">@style/tabtextcolor</item>
    </style>

    <style name="MyTheme.ActionBarStyle"parent="@android:style/Widget.Holo.Light.ActionBar">
         <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item
    </style>

    <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textColor">@color/red</item>
    </style>

    <style name="tabtextcolor" parent="@android:style/Widget.Holo.Light.ActionBar.TabText">
        <item name="android:textColor">@android:color/white</item>
    </style>
</resources>