.net Maui style on this component requires your app theme to be Theme.MaterialComponents

Jerod Motley 0 Reputation points
2023-11-20T17:53:21.74+00:00

I have an Android app that I migrated from Xamarin to .NET Maui. I started by creating an empty Maui project and bringing in the pages and getting it to compile and run. This was successful in getting the app to run.

However the next phase was a critical binding library project that had a UI component. This library contained an activity that is pushed on top of the mainactivity in the old Xamarin project. The problem is, the new maui project did not have a mainactivity. When the mainactivity from the Xamarin project was pulled, it would start before the first Maui page and I'm now getting an error "The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant)."

Break points show that we are indeed hitting the mainactivity before we hit the first Maui page. I'm sure there's a critical step that I'm missing but any thoughts would be appreciate.


namespace com
{ 


[Activity(Name = "com.com.MainActivity", Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] 

public class MainActivity : Microsoft.Maui.MauiAppCompatActivity {

 private UiState m_state;
 private static Intent m_frontCaptureResult;

    public static MainActivity Instance;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        Instance = this;
    }
}
}

Layout from Xamarin

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

<!--stuff-->

    </LinearLayout>
    
</ScrollView>
Developer technologies | .NET | Xamarin
Developer technologies | .NET | .NET MAUI
{count} votes

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.