Create own theme on Android in .NET MAUI

Simon 1 Reputation point
2022-09-13T11:17:48.297+00:00

On Android in .NET MAUI there is the MainActivity in the Platforms -> Android folder, which is structured as follows by default:

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]  
public class MainActivity : MauiAppCompatActivity  
{  
}  

It uses the theme "@STYLE /Maui.SplashTheme". Is this automatically generated at compile time? How can I create my own theme where I can add my own values and that inherits from SplashTheme?

Developer technologies .NET .NET MAUI
{count} votes

2 answers

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2022-09-14T05:12:44.987+00:00

    Hello,

    Referring to this official documentation Add a splash screen to a .NET MAUI app project, you could find the following content:

    On Android, the splash screen is added to your app package as Resourcs/values/maui_colors.xml and Resources/drawable/maui_splash_image.xml.
    .NET MAUI apps use the Maui.SplashTheme by default, which ensures that a splash screen will be displayed if present. Therefore, you should not specify a different theme in your manifest file or in your MainActivity class.

    Therefore, it is not recommended to replace the Maui.SplashTheme.

    If you want to theme your MAUI app, please refer to Theme an app.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. John Ureke 1 Reputation point
    2023-03-13T11:49:09.84+00:00

    I wish people would ANSWER THE QUESTION instead of saying, "You're not supposed to do this."

    You inherit it in your own theme just like every other Android app.

    Project/Platforms/Android/Resources/styles.xml:

    
    <?xml version="1.0" encoding="utf-8" ?>
    <resources>
        <style name="MyAppTheme" parent="Maui.SplashTheme">
            <item name="android:colorPrimary">#ff00ff</item>
            <item name="android:colorPrimaryDark">#00ff00</item>
        </style>
    </resources>
    

    Project/Platforms/Android/MainActivity.cs

    
    namespace Project
    {
    
        [Activity(Theme = "@style/MyAppTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density, ScreenOrientation = ScreenOrientation.Portrait)]
        public class MainActivity : MauiAppCompatActivity
        {
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.