Created
March 25, 2016 10:50
-
-
Save gabouh/1ea5f7a1887414f1fd80 to your computer and use it in GitHub Desktop.
NativeScript Splash Screen for Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File from app/App_Resources/Android/AndroidManifest.xml | |
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="__PACKAGE__" | |
android:versionCode="1" | |
android:versionName="1.0"> | |
<supports-screens | |
android:smallScreens="true" | |
android:normalScreens="true" | |
android:largeScreens="true" | |
android:xlargeScreens="true"/> | |
<uses-sdk | |
android:minSdkVersion="17" | |
android:targetSdkVersion="__APILEVEL__"/> | |
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | |
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | |
<uses-permission android:name="android.permission.INTERNET"/> | |
<application | |
android:name="com.tns.NativeScriptApplication" | |
android:allowBackup="true" | |
android:icon="@drawable/icon" | |
android:label="@string/app_name" | |
android:theme="@style/SplashTheme" > | |
<activity | |
android:name="com.tns.NativeScriptActivity" | |
android:label="@string/title_activity_kimera" | |
android:configChanges="keyboardHidden|orientation|screenSize"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
<activity android:name="com.tns.ErrorReportActivity"/> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File from app/app.js | |
var application = require("application"); | |
// check the current platform (we are interested in android only) | |
// alternatively, you may have app.android.js and app.ios.js | |
var platform = require("platform"); | |
if(platform.device.os === platform.platformNames.android) { | |
application.onLaunch = function(intent) { | |
// hook the onActivityCreated callback upon application launching | |
application.android.onActivityCreated = function(activity) { | |
// apply the default theme once the Activity is created | |
// Changing the SplashTheme for AppTheme | |
var id = activity.getResources().getIdentifier("AppTheme", "style", activity.getPackageName()); | |
activity.setTheme(id); | |
} | |
} | |
} | |
application.start({ moduleName: "main-page" }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File from platforms/android/src/main/res/values/styles.xml | |
<?xml version="1.0" encoding="utf-8"?> | |
<resources xmlns:android="http://schemas.android.com/apk/res/android"> | |
<style name="AppThemeBase" parent="Theme.AppCompat.Light.NoActionBar"> | |
<item name="toolbarStyle">@style/NativeScriptToolbarStyle</item> | |
<item name="colorPrimary">@color/ns_primary</item> | |
<item name="colorPrimaryDark">@color/ns_primaryDark</item> | |
<item name="colorAccent">@color/ns_accent</item> | |
</style> | |
<style name="SplashThemeBase" parent="Theme.AppCompat.Light.NoActionBar"> | |
<item name="android:windowFullscreen">false</item> | |
<item name="android:windowActionBar">true</item> | |
<item name="android:windowNoTitle">true</item> | |
<item name="android:windowContentOverlay">@null</item> | |
<item name="android:windowBackground">@drawable/splashscreen</item> | |
</style> | |
<style name="AppTheme" parent="AppThemeBase"> | |
</style> | |
<style name="SplashTheme" parent="SplashThemeBase"> | |
</style> | |
<style name="NativeScriptToolbarStyleBase" parent="Widget.AppCompat.Toolbar"> | |
<item name="android:background">@color/ns_primary</item> | |
<item name="theme">@style/ThemeOverlay.AppCompat.ActionBar</item> | |
<item name="popupTheme">@style/ThemeOverlay.AppCompat</item> | |
</style> | |
<style name="NativeScriptToolbarStyle" parent="NativeScriptToolbarStyleBase"> | |
</style> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you. Works great The only difference for me was that I had to put the styles.xml in the app/App_Resources/Android/values (creating values manually).