Skip to content

Instantly share code, notes, and snippets.

@GSala
Last active August 29, 2015 14:25
Show Gist options
  • Save GSala/e9c0b70f955896c83603 to your computer and use it in GitHub Desktop.
Save GSala/e9c0b70f955896c83603 to your computer and use it in GitHub Desktop.
Making a Splash Screen (25/7/2015)
Assuming you have a theme called AppTheme, your launcher theme would be:
<style name="AppTheme.Launcher">
<item name="android:windowBackground">@drawable/launch_screen</item>
<item name="colorPrimaryDark"></item>
</style>
But drawable/launch_screen can’t be just a simple image, unfortunately - it’ll end up stretched to fill the entire screen.
Instead, you can use an XML file such as:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<!-- The background color, preferably the same as your normal theme -->
<item android:drawable="@android:color/white"/>
<!-- Your product logo - 144dp color version of your app icon -->
<item>
<bitmap
android:src="@drawable/product_logo_144dp"
android:gravity="center"/>
</item>
</layer-list>
Apply your theme to your activity in your AndroidManifest.xml using android:theme="@style/AppTheme.Launcher".
The easiest way to transition back to your normal theme is to call setTheme(R.style.AppTheme) before super.onCreate():
public class MyMainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// Make sure this is before calling super.onCreate and setContentView
setTheme(R.style.Theme_MyApp);
super.onCreate(savedInstanceState);
// ...
}
}
by Ian Lake - https://plus.google.com/+AndroidDevelopers/posts/Z1Wwainpjhd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment