我一直试图解决这个问题3个小时,但没有找到任何答案。这是我的v21 \ styles.xml代码。更改操作栏的displayOptions有效,但似乎没有任何改变文本的颜色!
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/colorBackground</item>
<item name="android:alertDialogTheme">@style/MyDialogTheme</item>
<item name="android:color">@color/colorSecondary</item>
</style>
<style name="PreferencesTheme" parent="AppTheme">
<item name="android:textColorPrimary">@color/colorSecondary</item>
<item name="android:textColorSecondary">@color/colorSecondaryFaded</item>
<item name="android:listSeparatorTextViewStyle">@style/ListSeparatorText</item>
<item name="colorControlNormal">@color/colorSecondary</item>
<item name="actionBarStyle">@style/ActionBarTheme</item>
</style>
<style name="ListSeparatorText" parent="android:Widget.TextView">
<item name="android:background">@color/colorBackgroundLight</item>
<item name="android:color">@color/colorBackgroundLight</item>
</style>
<style name="ActionBarTheme" parent="Widget.AppCompat.Light.ActionBar.Solid">
<item name="displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:textColorPrimary">@color/colorSecondary</item>
<item name="android:titleTextAppearance">@style/ActionBar.Title</item>
</style>
<style name="ActionBar.Title">
<item name="android:textColorPrimary">@color/colorSecondary</item>
</style>
我的设置活动onCreate,如果这有用。
public class SettingsActivity extends AppCompatPreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupActionBar();
getFragmentManager().beginTransaction().replace(android.R.id.content,
new GeneralPreferenceFragment()).commit();
}
/**
* Set up the {@link android.app.ActionBar}, if the API is available.
*/
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
// Show the Up button in the action bar.
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
答案 0 :(得分:2)
由于另外一个埋在互联网上的帖子,我又花了4个小时找到了这个。我需要使用actionBarTheme而不是actionBarStyle。天啊,这真是一种痛苦!
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowBackground">@color/colorBackground</item>
<item name="android:alertDialogTheme">@style/MyDialogTheme</item>
</style>
<style name="PreferencesTheme" parent="AppTheme">
<item name="android:textColorPrimary">@color/colorSecondary</item>
<item name="android:listSeparatorTextViewStyle">@style/ListSeparatorText</item>
<!-- This attribute alone sets the colour of the text to the parent text colour-->
<item name="actionBarTheme">@style/PreferencesTheme.ActionBarTheme</item>
</style>
<style name="ListSeparatorText" parent="android:Widget.TextView"><!--parent is optional -->
<item name="android:background">@color/colorBackgroundLight</item>
<item name="android:color">@color/colorBackgroundLight</item>
</style>
<style name="PreferencesTheme.ActionBarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<!-- THIS is where you can color the arrow -->
<item name="colorControlNormal">@color/colorBackgroundLight</item>
<item name="android:textColorPrimary">@color/colorBackground</item>
</style>