Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create splash screen theme on compose theme.kt file

I want to moving all theme related xml code to compose file. There is a splash screen xml code, is it possible to let it in compose style?

<!-- Splash screen theme. -->
<style name="splashScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_screen</item>
</style>

@Composable
fun splashScreenTheme() {

}
like image 638
ccd Avatar asked Oct 04 '20 07:10

ccd


People also ask

How do I create a splash screen image?

The most straightforward way to create a simple splash screen was to create a dedicated theme overriding android:windowBackground with a drawable containing branding colors or a bitmap of a logo. The theme was set as an attribute of the launcher activity in AndroidManifest. xml.

How do I add a splash screen to Kotlin?

Note that select Kotlin as the programming language. Go to app > java > first package name > right-click > New > Activity > Empty Activity and create another activity and named it as SplashScreen. Edit the activity_splash_screen. xml file and add image, text in the splash screen as per the requirement.

What is splash screen in Android?

Splash screens (also known as launch screens) provide a simple initial experience while your mobile app loads. They set the stage for your application, while allowing time for the app engine to load and your app to initialize. This guide teaches you how to use splash screens appropriately on iOS and Android.

How to implement light and dark themes in compose?

Dark theme In Compose, you implement light and dark themes by providing different sets of Colors to the MaterialTheme composable, and consuming colors through the theme:

What is a material theme?

A Material Theme comprises color, typography and shape attributes. When you customize these attributes, it automatically reflected your changes in the components. We can customize the colors, typography, shapes, and themes using these files, 1. Colors First two characters 0x tell the compiler that this is a hexadecimal number.

What is a material theme in jetpack?

A Material Theme comprises color , typography and shape attributes. When you customize these attributes, your changes are automatically reflected in the components you use to build your app. Jetpack Compose implements these concepts with the MaterialTheme composable:

What is a splash screen?

Splash Screen is usually the first screen that represents your application through the logo or name of the application. It stays for few seconds and then automatically leads you to your main screen. You can use your logo or any kind of informative text that signifies your application.


1 Answers

As of Compose 1.0.1 / August 2021, there is no way to do this completely in Compose. I am currently using the XML/android:windowBackground based solution in the OP for my app which is pretty much entirely Compose otherwise.

However, note that Android 12 is introducing a SplashScreen API which lets you define a splash screen consisting of an adaptive icon and solid background colour.

Also, remember that things like date/time pickers are still not yet available natively in Compose, so if you use the Material Components library for that, you will still need the XML style files.

like image 167
machfour Avatar answered Oct 17 '22 01:10

machfour