Skip to content
This repository was archived by the owner on Jul 11, 2025. It is now read-only.

Commit cf13e30

Browse files
committed
SplashScreen: Fix the theme switch
Fix the theme switch by removing a call to Activity#create(). It seems to be no longer necessary. Also update the splash background color so that the light/dark themes are easier to tell apart during splash screen. Change-Id: I03b1b3fcb4550e2537fdcf1f5860276161ac4462
1 parent 288ef55 commit cf13e30

File tree

10 files changed

+36
-15
lines changed

10 files changed

+36
-15
lines changed

SplashScreen/app/build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ plugins {
2020
}
2121

2222
android {
23+
namespace 'com.example.android.splashscreen'
24+
testNamespace 'com.example.android.splashscreen.test'
2325
compileSdkVersion 33
2426

2527
defaultConfig {
@@ -52,10 +54,10 @@ dependencies {
5254
// Use the SplashScreen compat library.
5355
implementation 'androidx.core:core-splashscreen:1.0.0'
5456

55-
implementation 'androidx.core:core-ktx:1.8.0'
56-
implementation 'androidx.activity:activity-ktx:1.5.1'
57-
implementation 'androidx.appcompat:appcompat:1.5.0'
58-
implementation 'com.google.android.material:material:1.6.1'
57+
implementation 'androidx.core:core-ktx:1.9.0'
58+
implementation 'androidx.activity:activity-ktx:1.6.1'
59+
implementation 'androidx.appcompat:appcompat:1.5.1'
60+
implementation 'com.google.android.material:material:1.7.0'
5961

6062
def lifecycle_version = '2.5.1'
6163
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

SplashScreen/app/src/androidTest/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
-->
1717
<manifest
1818
xmlns:android="http://schemas.android.com/apk/res/android"
19-
package="com.example.android.splashscreen.test">
19+
>
2020

2121
<!-- Export the activities from AndroidX Testing Library. -->
2222
<application>

SplashScreen/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
~ See the License for the specific language governing permissions and
1515
~ limitations under the License.
1616
-->
17-
<manifest
18-
xmlns:android="http://schemas.android.com/apk/res/android"
19-
package="com.example.android.splashscreen">
17+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2018

2119
<application
2220
android:allowBackup="false"

SplashScreen/app/src/main/java/com/example/android/splashscreen/MainActivity.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,11 @@ abstract class MainActivity : AppCompatActivity() {
5050

5151
// Show the in-app dark theme settings. This is available on API level 31 and above.
5252
if (Build.VERSION.SDK_INT >= 31) {
53-
var previousMode: Int? = null
5453
viewModel.nightMode.observe(this) { nightMode ->
5554
val radioButtonId = radioButtonId(nightMode)
5655
if (binding.theme.checkedRadioButtonId != radioButtonId) {
5756
binding.theme.check(radioButtonId)
5857
}
59-
if (previousMode == null) previousMode = nightMode
60-
if (previousMode != nightMode) recreate()
6158
}
6259
binding.theme.setOnCheckedChangeListener { _, checkedId ->
6360
viewModel.updateNightMode(nightMode(checkedId))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 2022 The Android Open Source Project
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<resources>
18+
<color name="splash_screen_background">@color/blue_gray_900</color>
19+
</resources>

SplashScreen/app/src/main/res/values-night/themes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
<resources xmlns:tools="http://schemas.android.com/tools">
1818
<style name="Base.Theme.App" parent="Theme.MaterialComponents.NoActionBar">
1919
<item name="android:windowLightStatusBar" tools:targetApi="23">false</item>
20+
<item name="android:windowLightNavigationBar" tools:targetApi="27">false</item>
2021
</style>
2122
</resources>

SplashScreen/app/src/main/res/values/colors.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@
1919
<color name="lime_700">#AFB42B</color>
2020
<color name="blue_gray_500">#607D8B</color>
2121
<color name="blue_gray_700">#455A64</color>
22+
<color name="blue_gray_900">#263238</color>
23+
24+
<color name="splash_screen_background">@color/lime_500</color>
2225
</resources>

SplashScreen/app/src/main/res/values/themes.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
<style name="Base.Theme.App" parent="Theme.MaterialComponents.Light.NoActionBar">
2020
<item name="android:windowLightStatusBar" tools:targetApi="23">true</item>
21+
<item name="android:windowLightNavigationBar" tools:targetApi="27">true</item>
2122
</style>
2223

2324
<!--
@@ -60,7 +61,7 @@
6061
<!-- The background color behind the icon. -->
6162
<item name="windowSplashScreenIconBackgroundColor">@color/lime_700</item>
6263
<!-- The background color for the splash screen. -->
63-
<item name="windowSplashScreenBackground">@color/lime_500</item>
64+
<item name="windowSplashScreenBackground">@color/splash_screen_background</item>
6465
<!-- The duration, in milliseconds, of the icon animation of the splash screen. -->
6566
<item name="windowSplashScreenAnimationDuration">1000</item>
6667
<!-- The 'core-splashscreen' switches the theme back to this after splash screen. -->

SplashScreen/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
*/
1616

1717
buildscript {
18-
ext.kotlin_version = '1.7.10'
18+
ext.kotlin_version = '1.7.20'
1919
repositories {
2020
google()
2121
mavenCentral()
2222
}
2323
dependencies {
24-
classpath 'com.android.tools.build:gradle:7.2.2'
24+
classpath 'com.android.tools.build:gradle:7.3.1'
2525
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2626
}
2727
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Thu Jul 29 11:47:27 JST 2021
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)