How to change PreferenceActivity theme?

前端 未结 5 972
执念已碎
执念已碎 2020-12-18 21:45

I\'m trying to change the theme for the PreferenceActivity in my app and I just can\'t get it to work.

This is the xml:

    

        
5条回答
  •  失恋的感觉
    2020-12-18 22:47

    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.

提交回复
热议问题