Had a crash while trying to use the new TextInputField
for Android and wanted to share my solution.
Trying the new TextInputField in the android appcomp
Use the following:
View view = LayoutInflator.from(getActivity()).inflate(R.layout.your_layout_file,parent,false);
Using implementation 'com.google.android.material:material:1.1.0' all you have to do is use your XML tags like this: <com.google.android.material.textfield.TextInputLayout for it to work...In my case it applies to my <com.google.android.material.textfield.TextInputEditText as well. Happy coding!...
for me work changes from EditText to TextInputEditText
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/date_raffle"/>
</android.support.design.widget.TextInputLayout>
I got the same issue when inflating XML containing TextInputLayout
.
The problem was fixed by setting the correct Style on my application. Just like it says here : android design support library
I've the following issue
Caused by: android.view.InflateException: Binary XML file line #38: Error inflating class android.support.design.widget.TextInputLayout
My style.xml was
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material">
<!-- Customize your theme here. -->
</style>
</resources>
As it said in this post on Design Support Library
Note that as the Design library depends on the Support v4 and AppCompat Support Libraries, those will be included automatically when you add the Design library dependency.
So NO NEED TO ADD the following line inside the gradle file
compile 'com.android.support:appcompat-v7:22.2.0'
I found the link behove explaining that the Design Support Library is part of the AppCompat and it require the AppCompat Theme base to work. So I've modify my style.xml to be
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
And it worked.
just to be clear as of Android Studio 3.*
this is now changed to
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
(if this goes red a squiggly when you add it accept the version Android Studio wants to suggest)
this needs to be inside the
dependencies {}
section of build.gradle (Module:app)
so it looks like this
dependencies {
...
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
}
then hit sync now
None of the solution worked for me. I am using
compile 'com.android.support:appcompat-v7:28.0.0'
compile 'com.android.support:design:28.0.0'
Tried all the soluton. My app runs perfectly in devices with lower sdk. But crashes in newer( greater than sdk 26) devices. But after scratching head for 2 days finally got the solution.
my layout editor showed the error of
The following classes could not be instantiated:
- android.support.design.widget.TextInputLayout
But it did not gave me enough information to work with. It was not until I looked at other errors at the layout editor. Under render problem I found that
Couldn't resolve resource @string/path_password_strike_through
I finally got the solution after investigating this render problem. All you need to do is add
app:passwordToggleDrawable="@string/string_name"
in your TextInputLayout xml file.
<android.support.design.widget.TextInputLayout
android:id="@+id/login_input_layout_password"
android:layout_width="match_parent"
app:passwordToggleDrawable="@drawable/ic_lock_outline_grey600_24dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_marginTop="10dp"
android:backgroundTint="@color/colorAccent"
app:boxStrokeColor="#555"
android:textColorHint="@color/colorPrimary">
<EditText
android:id="@+id/login_input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.design.widget.TextInputLayout>