Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

TextInputLayout not inflating

Hi folks

I am using Xamarin android with visual studio. I have the floating text working using the following

  1. Theme = Theme.AppCompat.Light.DarkActionBar
  2. <android.support.design.widget.TextInputLayout>
  3. MainActivity : AppCompatActivity
  4. using Android.Support.V7.App

What I can't get working is the following:

  1. Theme = android:Theme.Material
  2. <android.support.design.widget.TextInputLayout>
  3. MainActivity : Activity

I get the following error:
Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.design.widget.TextInputLayout

My understanding is that the Android.Support.V7.App is needed for API < 23. I am targetting 22+

Would be really grateful if anyone can explain why or can spot why it isn't working.

Many thanks

Tagged:

Answers

  • RofiqSetiawanRofiqSetiawan USMember ✭✭✭

    @kal67

    Please make sure you have installed Xamarin.Android.Support.Design nuget.

  • kal67kal67 Member

    Hi RofiqSetiawan

    Many thanks for your reply. Yes I have installed v25.4.02 of Xamarin.Android.Support.Design.

    If I show you what I have maybe you can spot what is needed. I'm sure it's something really trivial but I just can see what. I thought it might be a using statement so added using Android.Support.Design

    I can get it all to work if using AppCompat etc but I thought you only used AppCompat if you are targetting API < 22.

    MainActivity.cs

            using Android.App;
            using Android.Widget;
            using Android.OS;
            using Android.Support.Design;
    
            namespace FloatingTextMaterialDesignDemo
            {
                [Activity(Label = "FloatingTextMaterialDesignDemo", MainLauncher = true)]
                public class MainActivity : Activity
                {
                    protected override void OnCreate(Bundle savedInstanceState)
                    {
                        SetTheme(Resource.Style.MyTheme);
                        base.OnCreate(savedInstanceState);
    
                        // Set our view from the "main" layout resource
                        SetContentView(Resource.Layout.Main);
                    }
                }
            }
    

    Unhandled Exception - happens on **SetContentView(Resource.Layout.Main);**

    Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.design.widget.TextInputLayout occurred

    main.axml

                <LinearLayout xmlns:android=..."
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
      <android.support.design.widget.TextInputLayout
                android:id="@+id/name_et_textinputlayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"  >
    
                <EditText
                    android:id="@+id/FeedBackerNameET"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:hint="hinttext"
                    android:inputType="textPersonName|textCapWords" />
         </android.support.design.widget.TextInputLayout>
    </LinearLayout>
    

    styles.xml

        <?xml version="1.0" encoding="utf-8" ?>
        <resources> 
            <!-- Base theme 
        <style name="MyTheme" parent="android:Theme.Material">            
            <!-- colorPrimary is used for the default action bar background -->
            <item name="colorPrimary">#2196F3</item>
            <!-- colorPrimaryDark is used for the status bar -->
            <item name="colorPrimaryDark">#1976D2</item>
            <!-- colorAccent is used as the default value for colorControlActivated
                 which is used to tint widgets -->
            <item name="colorAccent">#FF4081</item>       
          </style>
        </resources>
    
Sign In or Register to comment.