我知道这个问题有很多问题,但我无法让它工作,颜色保持默认蓝色。我试图更改标签的突出显示颜色。我主要遵循本教程(http://blog.alwold.com/2013/08/28/styling-tabs-in-the-android-action-bar/)。
现在我的values/styles.xml
我有以下代码:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
<item name="android:actionBarStyle">@style/ActionBarWithoutTitle</item>
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarTabStyle">@style/MyActionBar</item>
<item name="actionBarTabStyle">@style/MyActionBar</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="MyActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">@drawable/tab_bar_background</item>
<item name="background">@drawable/tab_bar_background</item>
</style>
除此之外,我有一个可绘制的状态列表以及另外两个设置一些颜色的列表。最重要的是,我在AndroidManifest.xml(AppBaseTheme)中设置了主题,如下所示:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme" >
<activity
android:name="com.stevesandco.miajournal.MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我也理解在values-v11和values-v14文件夹中,还应该添加与android版本对应的样式。唯一的问题是,在向<item name="android:background">@drawable/tab_bar_background</item>
添加values-v14\styles.xml
时,应用程序崩溃了。我不确定我是否遗漏了一些可能是我可能忘记的简单事情。
values-v11\styles.xml
:
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 11 theme customizations can go here. -->
<item name="background">@drawable/tab_bar_background</item>
</style>
values-v14\styles.xml
:
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
<item name="android:background">@drawable/tab_bar_background</item>
</style>