4

I have a preferenceActivity in my application and I have tried to set the preference style using the following theme:

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="MyPreferenceTheme" parent="android:Theme.Translucent">
    <item name="android:preferenceStyle">@style/MyPreference</item>
    <item name="android:windowBackground">@color/transparent_black</item>
</style>

<style name="MyPreference" parent="@android:style/Preference">
    <item name="android:layout">@layout/preference</item>
</style>

<color name="transparent_black">#BB000000</color>

So I know that the theme is loading as the background is colored correctly. However my custom preferenceLayout (res/layout/preference.xml) is not getting applied to any of the preferences inside my preferenceActivity.

Is this the correct way to achieve theming of the preferences? or have I missed something? Thanks in advance :)

stealthcopter
  • 13,964
  • 13
  • 65
  • 83

2 Answers2

4

I found that it's best not to use parent="android:style/Preference" as it doesn't seem to apply the style I'm trying to override it with. Style your layout that you're using (@layout/preference) and drop the inheritance from the android:style/Preference. It worked for me when I had to do the same.

so it should be:

<style name="MyPreference">
    <item name="android:layout">@layout/preference</item>
</style>

Good luck!

Paul
  • 120
  • 1
  • 8
0

That's a bug. See this issue.

You can "fix" it by assigning an ID for every PreferenceScreen. Then, you do this for every :

((PreferenceScreen) preferenceScreen).getDialog().getWindow().setBackgroundDrawable(drawable);

Good luck
Tom

TomTasche
  • 5,448
  • 7
  • 41
  • 67
  • Afraid you've misread the question. I'm already aware of that bug, I actually posted a question on that before: http://stackoverflow.e com/questions/2755005/nested-preference-screens-lose-theming but this is to do with overriding the layout for each preference (the title, summary and widget) – stealthcopter Feb 28 '11 at 09:01