我有一个活动 (MainActivity.java) 用作启动屏幕,同时加载主要片段并且其他功能在后台发生。此启动屏幕始终显示棕色瓷砖背景和图标。我想要的是仅当变量 dayMode 为 false(Constants.java 中的变量)时显示背景(在 R.style.AppTheme_NoActionBar_LauncherNight 中)。否则,背景应该是 R.style.AppTheme_NoActionBar_LauncherDay 中的背景(白色背景和相同的图标)。
如果我在我的清单的 android:theme 部分指定一个或另一个背景,它会很好地显示。但我想要的是以编程方式设置一个或另一个主题,具体取决于 dayMode 的值,在活动的 onCreate 方法上。这是行不通的。
正如我在其他答案中读到的那样,我在调用 super.onCreate 或 setContentView 之前尝试使用 setTheme,但它不起作用。我只找到解释调用 setTheme 和 setContentView 的顺序的答案,但它们并没有解决这个问题。
我的风格:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="autoCompleteTextViewStyle">@style/cursorColor</item>
<item name="android:textColorSecondary">@color/yellow_light</item>
</style>
<style name="AppTheme.NoActionBar.LauncherNight">
<item name="android:windowBackground">@drawable/launch_screen</item>
</style>
<style name="AppTheme.NoActionBar.LauncherDay">
<item name="android:windowBackground">@drawable/launch_screen_day</item>
</style>
我的清单:
<activity
android:name="com.AlbaRam.myApp.MainActivity"
android:configChanges="keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar.LauncherNight"
android:launchMode="singleInstance"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
白猪掌柜的
Cats萌萌
肥皂起泡泡
相关分类