Skip to content

Commit ddca267

Browse files
authored
Merge pull request #125 from christophermark/custom-android-theming
Optional theming to Android splash screen
2 parents 5fabc60 + 09efeb1 commit ddca267

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public class MainApplication extends Application implements ReactApplication {
9999
2. Go to `node_modules``react-native-splash-screen` and add `SplashScreen.xcodeproj`
100100
3. In XCode, in the project navigator, select your project. Add `libSplashScreen.a` to your project's `Build Phases``Link Binary With Libraries`
101101
4. To fix `'SplashScreen.h' file not found`, you have to select your project → Build Settings → Search Paths → Header Search Paths to add:
102-
102+
103103
`$(SRCROOT)/../node_modules/react-native-splash-screen/ios`
104104

105105

@@ -203,14 +203,29 @@ Open `android/app/src/main/res/values/styles.xml` and add `<item name="android:w
203203

204204
If you want to customize the color of the status bar when the splash screen is displayed:
205205

206-
Create `android/app/src/main/res/values/colors.xml` and add
206+
Create `android/app/src/main/res/values/colors.xml` and add
207207
```xml
208208
<?xml version="1.0" encoding="utf-8"?>
209209
<resources>
210-
<color name="primary_dark"><!-- Colour of your status bar here --></color>
210+
<color name="status_bar_color"><!-- Colour of your status bar here --></color>
211211
</resources>
212212
```
213213

214+
Create a style definition for this in `android/app/src/main/res/values/colors.xml`:
215+
```xml
216+
<?xml version="1.0" encoding="utf-8"?>
217+
<resources>
218+
<style name="SplashScreenTheme" parent="SplashScreen_SplashTheme">
219+
<item name="colorPrimaryDark">@color/status_bar_color</item>
220+
</style>
221+
</resources>
222+
```
223+
224+
Change your `show` method to include your custom style:
225+
```java
226+
SplashScreen.show(this, false, R.style.SplashScreenTheme);
227+
```
228+
214229
### iOS
215230

216231
Customize your splash screen via LaunchImage or LaunchScreen.xib,

android/src/main/java/org/devio/rn/splashscreen/SplashScreen.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,27 @@
1414
* Email:crazycodeboy@gmail.com
1515
*/
1616
public class SplashScreen {
17+
private static int NULL_ID = 0;
1718
private static Dialog mSplashDialog;
1819
private static WeakReference<Activity> mActivity;
1920

2021
/**
2122
* 打开启动屏
2223
*/
23-
public static void show(final Activity activity, final boolean fullScreen) {
24+
public static void show(final Activity activity, final boolean fullScreen, final int themeResId) {
2425
if (activity == null) return;
2526
mActivity = new WeakReference<Activity>(activity);
2627
activity.runOnUiThread(new Runnable() {
2728
@Override
2829
public void run() {
2930
if (!activity.isFinishing()) {
3031

31-
mSplashDialog = new Dialog(activity, fullScreen ? R.style.SplashScreen_Fullscreen : R.style.SplashScreen_SplashTheme);
32+
mSplashDialog = new Dialog(
33+
activity,
34+
themeResId != NULL_ID ? themeResId
35+
: fullScreen ? R.style.SplashScreen_Fullscreen
36+
: R.style.SplashScreen_SplashTheme
37+
);
3238
mSplashDialog.setContentView(R.layout.launch_screen);
3339
mSplashDialog.setCancelable(false);
3440

@@ -40,6 +46,13 @@ public void run() {
4046
});
4147
}
4248

49+
/**
50+
* 打开启动屏
51+
*/
52+
public static void show(final Activity activity, final boolean fullScreen) {
53+
show(activity, fullScreen, 0);
54+
}
55+
4356
/**
4457
* 打开启动屏
4558
*/

android/src/main/res/values/refs.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@
33
<item type="layout" name="launch_screen">
44
@layout/launch_screen
55
</item>
6-
<item type="color" name="primary_dark">
7-
@color/primary_dark
8-
</item>
96
</resources>

android/src/main/res/values/styles.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
<style name="SplashScreen_SplashTheme" parent="Theme.AppCompat.NoActionBar">
77
<item name="android:windowAnimationStyle">@style/SplashScreen_SplashAnimation</item>
8-
<item name="colorPrimaryDark">@color/primary_dark</item>
98
</style>
109
<style name="SplashScreen_Fullscreen" parent="SplashScreen_SplashTheme">
1110
<item name="android:windowFullscreen">true</item>

0 commit comments

Comments
 (0)