Open
Description
Android application type
Classic Xamarin.Android (MonoAndroid12.0, etc.), Android for .NET (net6.0-android, etc.)
Affected platform version
.NET 7, Visual Studio 2022 17.5.0
Description
Defining a FragmentContainerView with the android:name
or class
attributes throws at runtime (during inflation).
Steps to Reproduce
- Create a new Xamarin.Android project named "com.example.myapp".
- Create a new
MyFragment
class that inherits fromAndroidX.Fragment.App.Fragment
. - Insert the following XML inside the root tag in the main activity's layout file:
<androidx.fragment.app.FragmentContainerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="myapp.MyFragment"
android:id="@+id/my_fragment"/>
- Run the app - an
InflateException
is thrown (whereas a pure Java app would find the fragment class and inflate it). - Note that replacing the
<androidx.fragment.app.FragmentContainerView>
tag with<fragment>
does work as expected.
Did you find any workaround?
Use the old <fragment>
tag instead of <FragmentContainerView>
.
Relevant log output
Android.Views.InflateException: 'Binary XML file line #1 in com.example.myapp:layout/activity_main: Binary XML file line #1 in com.example.myapp:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView'