2016-06-22 10 views
0

私はこれを3時間解決しようとしていて、何の答えも見つかりませんでした。ここに私のv21 \ styles.xmlコードがあります。ここのアクションバーのdisplayOptionsを変更すると効果はありますが、テキストの色を変更するものはありません!PreferenceActivityのアクションバーのテキストの色を変更する方法

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

これが役に立ちましたら、私の設定アクティビティを作成してください。

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

APIレベル21以上で実行していますか?そうでない場合は、APIレベル<21のスタイルが必要です。 – danypata

+0

はい、API 23で動作しています。ありがとうございました。 –

答えて

0

インターネットに埋め込まれた別の投稿のおかげで、これを見つけるのにさらに4時間かかりました。 actionBarStyleの代わりにactionBarThemeを使用する必要がありました。 OMGこれは痛みでした!

<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> 
+0

これは私のためには機能しません –

+0

別の質問でコードを投稿しますか? –

+0

それは動作します、単に動作するためのアンドロイドマニフェストのテーマを他の方法で定義します –

関連する問題