Search code examples
androidandroid-preferencespreferenceactivity

styling conflict android actionbarsherlock with preferences


<style name="GCTheme" parent="Theme.Sherlock.Light"> 
    <item name="android:textSize">18sp</item>
    <item name="android:textColor">#FFFFFF</item>
    <item name="actionDropDownStyle">@style/MyDropDown</item>
    <item name="popupMenuStyle">@style/PopupMenu.Example</item>
</style> 

<style name="MyDropDown" parent="Widget.Sherlock.Spinner.DropDown.ActionBar"> 
   <item name="android:popupBackground">#7D7D7D</item>
</style> 

<style name="PopupMenu.Example" parent="@style/Widget.Sherlock.Light.ListPopupWindow">  
    <item name="android:popupBackground">#7D7D7D</item> 
</style>

The following code styles my action bar such that the title of the action bar is white and the action bar is bluish. The problem that I am faced with now is that, since I am using the Theme.Sherlock.Light, the settings on options menu will not display properly. Setting in the option menu extends PreferenceActivity and consists of the following code,

protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.perferences);
    }

The main problem here is that, the textColor for the action bar is set to be white and also the background that appears on this page is white, making the text impossible to read ... Does anyone have an idea so as to solve this problem.

I did try using this code

View v = new View(this);
v.setBackgroundColor(Color.GRAY);

in the settings activity, but it did not work.


Solution

  • So instead of using <item name="android:textColor">#FFFFFF</item> to set your title's color to white you should use this :

    <style name="Theme.MyApplications" parent="@style/Theme.Sherlock.Light.DarkActionBar">
        <item name="actionBarStyle">@style/ActionBar.Solid</item>
    </style>
    
    <style name="ActionBar.Title" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
        <item name="android:textColor">@android:color/white</item>
    </style>
    
    <style name="ActionBar.SubTitle" parent="TextAppearance.Sherlock.Widget.ActionBar.Subtitle">
        <item name="android:textColor">@android:color/white</item>
    </style>
    
    <style name="ActionBar.Solid" parent="@style/Widget.Sherlock.Light.ActionBar.Solid">
        <item name="titleTextStyle">@style/ActionBar.Title</item>
        <item name="subtitleTextStyle">@style/ActionBar.SubTitle</item>
    </style>
    

    This should do the trick for you.