locked
Binary XML file line #1: Error inflating class Button in xamarin.android RRS feed

  • Question

  • User246263 posted

    After splash screen I'm redirecting to login page. On login page's OnCreate() method when I set SetContentView(Resource.Layout.Login); I'm getting this error "Binary XML file line #1: Error inflating class Button". Following is my Login Page source code.

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@android:color/white">
    <!--android:orientation="vertical"-->
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="150dp"
        android:src="@drawable/thunder_logo"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_marginTop="30dp" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/login_mobile"
        android:layout_marginBottom="10dp"
        android:layout_above="@+id/login_password"
        android:background="@drawable/view_border"
        android:inputType="numberDecimal"
        android:drawableLeft="@drawable/login_phone_icon"
        android:fontFamily="roboto_light"
        android:hint="Mobile Number"
        android:singleLine="true"
        android:phoneNumber="true" />
     <!-- android:layout_gravity="center"-->
    <EditText
        android:id="@+id/login_password"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_above="@+id/login_login_button"
        android:background="@drawable/view_border"
        android:drawableLeft="@drawable/login_password_icon"
        android:drawableRight="@drawable/forgot_password_icon"
        android:inputType="textPassword"
        android:fontFamily="roboto_light"
        android:hint="Password"
        android:password="true"
        android:singleLine="true"
        android:layout_marginTop="5dp" />
    <!--android:layout_gravity="center"-->
    <Button
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:id="@+id/login_login_button"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="60dp"
        android:text="LOG IN"
        android:textColor="@color/primaryTextDefault"
        android:background="@drawable/button_bg" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:layout_marginBottom="20dp"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Sign up"
            android:padding="5dp"
            android:textSize="12sp"
            android:textStyle="bold"
            android:clickable="true"
            android:id="@+id/login_signup_text" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="12sp"
            android:text="as a personal app user."
            android:id="@+id/textView2" />
    </LinearLayout>
    </RelativeLayout>
    

    Following is the button_bg.xml file

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
      <item>
        <layer-list>
      <item>
        <shape        
          android:shape="rectangle"      
          android:configChanges="orientation"
          android:screenOrientation="portrait"
          android:layout_centerHorizontal="true">
    
          <gradient
              android:angle="90"
              android:endColor="?attr/colorPrimary"
              android:startColor="?attr/colorPrimary"
              android:type="linear" />
    
          <stroke android:width="1dip" 
                  android:color="?attr/colorPrimary" />
    
          <corners
              android:radius="3dip" />
          <padding
              android:bottom="3dp"
              android:left="0dp"
              android:right="0dp"
              android:top="3dp" />
        </shape>
      </item>     
        </layer-list>
      </item>
    </selector>
    

    Following is loginPage's OnCreate() method

    protected override void OnCreate(Bundle bundle)
        {
            try
            {
                base.OnCreate(bundle);
                var prefs =    PreferenceManager.GetDefaultSharedPreferences(Application.Context);
                var userSetTheme = prefs.GetString("userSetTheme", "");
                if (userSetTheme == "Theme_Green")
                {
                    SetTheme(Resource.Style.Theme_Green);
                }
                else if (userSetTheme == "Theme_Blue")
                {
                    SetTheme(Resource.Style.Theme_Blue);
                }
    
                SetContentView(Resource.Layout.Login);
    
                SignUp = FindViewById<TextView>(Resource.Id.login_signup_text);
                SignUp.Click += SignUpClick;
    
                MobileNumberEditText = FindViewById<EditText>(Resource.Id.login_mobile);               
    
                LoginButton = FindViewById<Button>(Resource.Id.login_login_button);
                LoginButton.Click += LoginButton_Click;
    
                PasswordEditText = FindViewById<EditText>(Resource.Id.login_password);              
                PasswordEditText.SetOnTouchListener(this);
    
                Typeface face = Typeface.CreateFromAsset(Application.Context.Assets, "fonts/google_material_design.ttf");
    
    
    
            }
            catch(Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Login OnCreate() error: " + ex.Message);
            }
        }  ``
    
    Wednesday, March 22, 2017 7:24 AM

All replies

  • User246263 posted

    @CraigDunn do you have solution? Please help.

    Thursday, March 23, 2017 7:11 AM
  • User218392 posted

    Extend your Activity with AppCompatActivity if you are not extending it may not work for you.

    Saturday, March 25, 2017 1:51 PM
  • User246263 posted

    @Arvindraja Thank you for the reply. I have resolved the problem. In my theme.xml file hex code was wrong. It was used for button background.

    Monday, April 3, 2017 6:33 AM