18

I want to integrate android.support.design.widget.TextInputLayout In my android application. I have copied the jar file android-support-design.jar from the sdk to my applications lib folder. I have added below code in my xml file for the Email EditText,

 <!-- Email Label -->
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp">
            <EditText android:id="@+id/input_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textEmailAddress"
                android:hint="Email" />
        </android.support.design.widget.TextInputLayout>

While add this code in my layout.xml file I am getting an error like,

Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be instantiated:
- android.support.design.widget.TextInputLayout (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.

How can i fix this issue...

4
  • I'm not sure how the mentioned code produced MockView cannot be cast to android.view.ViewGroup please show the code that uses a mocking library Commented Jul 17, 2016 at 17:13
  • Also, you should use Gradle dependencies rather than jar files. Less problems will arise Commented Jul 17, 2016 at 17:14
  • did you added the jar file to compile in gradle dependency Commented Jul 17, 2016 at 17:17
  • I am using Eclipse for development Commented Jul 17, 2016 at 17:32

8 Answers 8

51

replace

android.support.design.widget.TextInputLayout

with

com.google.android.material.textfield.TextInputLayout
Sign up to request clarification or add additional context in comments.

Comments

9

If you uses AndroidStudio, you should not include android-support-design.jar. Instead, write like below in your build.gradle:

dependencies {
    ...
    compile 'com.android.support:design:24.0.0'
    ...
}

Edit: If this doesn't work you are probably using a different version. In Windows, go to:

[android-sdk]\extras\android\m2repository\com\android\support\design

On Mac:

sdk/extras/android/m2repository/com/android/support/design

This directory holds a number of version folders. Use the latest version on your build.gradle.

3 Comments

I am using Eclipse for development
You should import support-v7-appcompat library. see stackoverflow.com/a/31431076/5183999
Thanks Its worked for me... I have added the library project from android-sdks\extras\android\support\design
7

add in the build.gradle following this line:

implementation 'com.android.support:design:28.0.0'

and use in the xml file:

 <com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/inputLayoutMobile"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/dimen_20dp"
                    android:layout_marginRight="@dimen/dimen_20dp"
                    android:hint="@string/phone_number"
                    android:visibility="gone"
                    android.support.design:layout_constraintTop_toBottomOf="@+id/inputLayoutAppServerUrl">

                    <com.google.android.material.textfield.TextInputEditText
                        android:id="@+id/edtTxtMobile"
                        style="@style/Style_TextView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:drawableLeft="@drawable/ic_smartphone"
                        android:drawablePadding="@dimen/dimen_10dp"
                        android:inputType="number"
                        android:singleLine="true"
                        android:scrollbars="vertical"
                        android:text="@={SettingViewModel.mMobileNo}"
                        android:textSize="@dimen/font_13sp" />
                </com.google.android.material.textfield.TextInputLayout>

1 Comment

Shouldn't we use androidx libraries?
1

I had similar problem, replace the TextInputLayout design pattern with below resolved for me:

com.google.android.material.textfield.TextInputLayout

Comments

1

The dependency your using is part of the Android support library which is now deprecated and no longer supported by Google. Instead, use this:
implementation 'com.google.android.material:material:<version>'
and replace <version> with the latest version from either Google's Maven Repository or MVN Repository

Perhaps you could read more from here Getting Started

Comments

1

For android androidX add this dependencies

implementation 'com.google.android.material:material:1.2.0'

Then try

Comments

0

If implementation, compile and api doesn't work try using classpath with latest version of material library you can find latest version on Google's Maven Repository

dependencies {
    .....
    classpath 'com.google.android.material:material:1.4.0-beta01'
    ....
}

Comments

-6

You are making mistake in giving id give id to TextInputLayout

1 Comment

there is no relevance of setting id , TextInputLayout is a part of material design library so we need to add the relevant library to get its intellisense autofill in xml.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.