Reputation: 839
I am trying to create a splash screen with 2 logos, one on the sender and one as a footer. But I didn't get such type of implementation in MAUI. Is there any way to do it on MAUI?
So I tried platform level integration like below for android.
Created splash_screen.xml
under Platforms/Android/Resources/layout
folder.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/icon1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/icon1" />
<ImageView
android:id="@+id/icon2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/icon1"
android:layout_centerHorizontal="true"
android:src="@drawable/icon2" />
</RelativeLayout>
Added icon1 and icone2 under Platforms/Android/Resources/drawable
folder.
Added theme on AndroidManifest
file under application
tag.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="@mipmap/appicon"
android:roundIcon="@mipmap/appicon_round"
android:supportsRtl="true"
android:theme="@style/SplashTheme">
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Added styles.xml
file under Platforms/Android/Resources/values
folder and added below code.
<resources>
<!-- Splash screen theme -->
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@layout/splash_screen</item>
</style>
</resources>
Finally on the MainActivity
added below code:
public class MainActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set the custom splash screen layout
SetContentView(Resource.Layout.splash_screen);
}
}
While running I getting the below exception:
Java.Lang.IllegalArgumentException: 'No view found for id 0x7f08014b (com.companyname.marianconsecration:id/navigationlayout_content) for fragment NavigationRootManager_ElementBasedFragment{f1d86d4} (a90f9cb5-b73f-4ac2-9767-c8bb9b057cb7 id=0x7f08014b)'
Upvotes: 1
Views: 202
Reputation: 224
Here is my solution, maui .net 8.0 targets android 14.0. and android used the Splash Screen since version 12.0. And according to the official document, the Splash Screen api can put two image: appicon and brand image.
Here's where you can store your two images.
Platforms/Android/Resources/drawable/icon1.jpg
Platforms/Android/Resources/drawable/icon2.jpg
Platforms/Android/MainActivity.cs
[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}
Platforms/Android/Resources/values/styles.xml
<resources>
<style name="Maui.SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowSplashScreenAnimatedIcon">@drawable/icon1</item>
<item name="android:windowSplashScreenBrandingImage">@drawable/icon2</item>
</style>
</resources>
Upvotes: 0