设置主题不适用于较低的API版本

时间:2013-05-27 10:25:03

标签: android themes

我想设置整个应用程序主题。我的代码在ICe​​-Creme Sandwich和更高版本中运行良好,但它不适用于较低版本,不会出现任何错误。

这是我的代码:

我在调用setcontentView();

之前使用以下代码设置主题
SharedPreferences pref=context.getSharedPreferences(HomeSAFEPref.HomeSAFEPref,0);
        int position= pref.getInt("BackgroundPosition", 0);

        switch (position) {
        case 0:

            context.setTheme(R.style.Background0);

            break;

        case 1:

            context.setTheme(R.style.Background1);

            break;

        case 2:

            context.setTheme(R.style.Background2);

            break;

        case 3:
            context.setTheme(R.style.Background3);
            break;

        case 4:
            context.setTheme(R.style.Background4);
            break;
        }

以上代码在较高版本中运行良好,但不适用于较低版本。

以下是样式代码:

<style name="Background0" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="android:windowBackground">@drawable/bigl_1</item>
        <item name="android:windowNoTitle">true</item>
    </style>

请建议

1 个答案:

答案 0 :(得分:4)

在调用super.onCreate()和setContentView()之前,应该设置主题。如果它仍然不起作用,那么它可能是框架的一个问题。

参考thisthis