Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply theme to <PreferenceScreen> elements of a <PreferenceCategory>

I have an activity that extends PreferenceActivity.

My theme : android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" is applied to the application level in the Manifest file.

Everything is getting the desired theme except the "PreferenceScreen" elements of "PreferenceCategory". They are still having the default black background. In simple words, the main Preference Category screen which has the parent Preference Screens are getting the theme but if I click on any of the PreferenceScreens to go to their element preferences(EditText etc etc), they are not getting the theme...

Any Idea why this might be happening?

The structure or preferences.xml is something like this :

<PreferenceCategory>

    <PreferenceScreen>
        <EditTextPreference>
        ...
        </EditTextPreference>
        <EditTextPreference>
        ...
        </EditTextPreference>
        ...
    </PreferenceScreen>

    <PreferenceScreen>
    ...
    </PreferenceScreen>

</PreferenceCategory>
like image 575
Vikas Singh Avatar asked Apr 19 '12 12:04

Vikas Singh


1 Answers

At last i found out how to change theme of "PreferenceActivity" programmatically(via java code)

To change theme just do like this:

        @Override
        public void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.Holo_Theme_Light);
        super.onCreate(savedInstanceState);
        }

Always call setTheme(R.style.yourtheme); method before super.onCreate(savedInstanceState); method. By doing this it will produce result as shown below.

enter image description here

That's all.

If yo call setTheme(R.style.yourtheme); method after super.onCreate(savedInstanceState); method it will produce result as shown below.

enter image description here

Note: Themes are not recognize by nested PreferenceScreen. To apply theme to that nested PreferenceScreen you have to make an another PreferenceActivity for that nested PreferenceScreen and call setTheme(R.style.yourtheme); method there.

like image 131
E Player Plus Avatar answered Sep 19 '22 18:09

E Player Plus