-
Notifications
You must be signed in to change notification settings - Fork 0
Android Development
In HomeScreen.kt, we display the logo using the following code:
@Composable
fun HeaderView() {
Image(
painter = painterResource(id = R.drawable.logo),
contentDescription = "Solara Logo",
modifier = Modifier
.size(200.dp)
.fillMaxWidth()
)
}
The logo is copied to src/main/solara_artifacts/logo.png
during the switching process. If you change the logo for
different brands, the new image will automatically be displayed.
To apply the brand theme, you can use this example:
@Composable
fun InfiniteApp() {
val navController = rememberNavController()
MaterialTheme(
colorScheme = MaterialTheme.colorScheme.copy(
primary = Color(BrandTheme.Colors.primary),
onPrimary = Color(BrandTheme.Colors.onPrimary),
secondary = Color(BrandTheme.Colors.secondary),
onSecondary = Color(BrandTheme.Colors.onSecondary),
surface = Color(BrandTheme.Colors.surface),
onSurface = Color(BrandTheme.Colors.onSurface),
background = Color(BrandTheme.Colors.background),
error = Color(BrandTheme.Colors.error),
onBackground = Color(BrandTheme.Colors.onBackground),
onError = Color(BrandTheme.Colors.onError),
)
) {
val isActive = remember { mutableStateOf(true) }
if (BrandConfig.instance.showSplashScreen && isActive.value) {
SplashScreen(isActive)
} else {
HomeScreen(navController = navController, title = stringResource(R.string.app_name))
}
}
}
Each color is referenced from BrandTheme.Colors
, which is generated by Solara during the switching process.
Solara simplifies accessing app configurations through BrandConfig
. Here's how you can retrieve the data:
@Composable
fun BrandInfoView() {
val brandConfig = BrandConfig.instance
Column(
modifier = Modifier.padding(16.dp)
) {
InfoText("Application ID:", brandConfig.applicationId)
InfoText("Version Name:", brandConfig.versionName)
InfoText("Version Code:", brandConfig.versionCode.toString())
InfoText("baseUrl:", brandConfig.baseUrl)
InfoText("showSplashScreen:", brandConfig.showSplashScreen.toString())
Spacer(modifier = Modifier.height(16.dp))
}
}
To add custom configurations for your brand, place the configuration in YOUR_BRAND/shared/brand_config
. For example:
- Brand 1 (
brand_config.json
)
{
"showSplashScreen": true,
"baseUrl": "https://www.google.com"
}
- Brand 2 (
brand_config.json
)
{
"showSplashScreen": false,
"baseUrl": "https://www.facebook.com"
}
To access these configurations, we call BrandConfig.instance
:
@Composable
fun BrandInfoView() {
val brandConfig = BrandConfig.instance
Column(
modifier = Modifier.padding(16.dp)
) {
InfoText("Application ID:", brandConfig.applicationId)
InfoText("Version Name:", brandConfig.versionName)
InfoText("Version Code:", brandConfig.versionCode.toString())
InfoText("baseUrl:", brandConfig.baseUrl)
InfoText("showSplashScreen:", brandConfig.showSplashScreen.toString())
Spacer(modifier = Modifier.height(16.dp))
}
}
For the full project, check the Infinite Android Project.
Achieve excellence! Don't just avoid errors!