Text input layout throws error on setError method - android

I am applying the setError() method on TextInputLayout and TextInputEditText but I am getting this error,
What I am trying to achieve is the error tooltip.I am in no mood of using any third party libraries to achieve this.\
Here is what I tried and none of these worked,
Error in TextInputLayout dont show again even call setErrorEnabled(true)
TextInputLayout setErrorEnabled doesn't create new TextView object
TextInputLayout.setError() leaves empty space after clearing the error
TextInputLayout not showing error message after clearing
setError for TextInputLayout showing Error
TextInputLayout error after enter value into edittext
textinputlayout errorenabled and showing errors
textinputlayout errorenabled and showing errors
TextInputLayout's errorview is not removed when removing error message
Gradle
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
Error Stacktrace,
Process: com.example.demo, PID: 31847
java.lang.UnsupportedOperationException: Failed to resolve attribute at index 24: TypedValue{t=0x3/d=0x1ec "res/color/secondary_text_material_dark.xml" a=1 r=0x1060120}
at android.content.res.TypedArray.getColor(TypedArray.java:449)
at android.widget.TextView.<init>(TextView.java:741)
at android.widget.TextView.<init>(TextView.java:674)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:62)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:58)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:54)
at android.support.design.widget.TextInputLayout.setErrorEnabled(TextInputLayout.java:602)
at com.example.demo.DemoActivity.canLogin(DemoActivity.java:163)
at com.example.demo.DemoActivity.access$000(DemoActivity.java:24)
at com.example.demo.DemoActivity$1.onClick(DemoActivity.java:54)
at android.view.View.performClick(View.java:5207)
at android.view.View$PerformClick.run(View.java:21177)
at android.os.Handler.handleCallback(Handler.java:742)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5527)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
Here is the XML
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="UserName"
android:theme="#style/txtIptLayout"
android:layout_marginTop="10dp"
app:backgroundTint="#color/white"
android:id="#+id/tilUsername"
app:errorTextAppearance="#style/Theme.AppCompat"
>
<android.support.design.widget.TextInputEditText
style="#style/txtEditTxtLayout"
app:backgroundTint="#color/white"
android:id="#+id/etUserName"
android:maxLines="1"
android:inputType="text"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:theme="#style/txtIptLayout"
app:passwordToggleEnabled="true"
app:passwordToggleDrawable="#drawable/ic_widget_icon_txtiptlayout"
app:passwordToggleTint="#color/white"
android:layout_marginTop="10dp"
app:backgroundTint="#color/white"
app:errorTextAppearance="#style/Theme.AppCompat"
android:id="#+id/tilPassword"
>
<android.support.design.widget.TextInputEditText
style="#style/txtEditTxtLayout"
android:inputType="textPassword"
android:id="#+id/etPassword"
app:backgroundTint="#color/white"
/>
</android.support.design.widget.TextInputLayout>
Here is what I am applying and this is where exactly the error is thrown,
tilPassword.setError("Password required");
tilPassword.setErrorEnabled(true);

Try this:
tilPassword.getEditText().setError("Password required");
tilPassword..setErrorEnabled(true);

Not sure how but removing the theme attribute in XML android:theme="#style/txtIptLayout" worked. The assumption would be that overriding the theme from XML will override the theme for the tooltip and hence the error.

Well this happens, when you try to override the theme from XML, it will override the default functionalities as well. i have faced similar issue where i was creating a style parenting TextAppearance.AppCompat.
Replacing it with Theme.AppCompat resolved my issue.

Related

How to set vector drawable into EditText under api 21?

In my application i want show vector drawable right of EditText.
I added this drawable vector from Vector Asset into android studio!
but when run application show me force close error.
Xml code :
<EditText
android:id="#+id/signInFrag_phoneEdt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:hint="#string/insertYourPhoneNumber"
android:maxLines="1"
android:drawableRight="#drawable/ic_phone_android"
android:paddingLeft="#dimen/_10sdp"
android:paddingRight="#dimen/_10sdp"
android:singleLine="true"
android:maxLength="11"
android:inputType="phone"
android:textColorHint="#color/colorLightGray"
android:textSize="#dimen/_12sdp"
android:drawableEnd="#drawable/ic_phone_android"/>
I added vectorDrawables.useSupportLibrary = true into android and defaultConfig on gradle.build file.
error message :
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_phone_android.xml from drawable resource ID #0x7f0700b3
at android.content.res.Resources.loadDrawable(Resources.java:2096)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.TextView.<init>(TextView.java:814)
at android.widget.EditText.<init>(EditText.java:60)
at androidx.appcompat.widget.AppCompatEditText.<init>(AppCompatEditText.java:73)
at androidx.appcompat.widget.AppCompatEditText.<init>(AppCompatEditText.java:69)
at androidx.app
Also i added this line into application class : AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
How can i fix this problem?
Give a try to
app:drawableEndCompat="#drawable/ic_phone_android"
The support should be included in build.gradle:
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
Add this line to your MainActivity
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)

After migrating to androidx: Didn't find class "androidx.constraintlayout.ConstraintLayout" on path: DexPathList

I've searched for an answer to my problem, as shown in the title of this question, and found Error inflating class androidx.constraintlayout.ConstraintLayout after migration to androidx, which aligns with the official migration instructions presented in Migrating to AndroidX. I took the information as requiring me to change android.support.constraint.ConstraintLayoutto androidx.constraintlayout.widget.ConstraintLayout, but this doesn't work for me.
I haven't found anything about what dependency to put in my gradle file, so I tried this (this is a shot in the dark):
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
which is accepted but when I tried:
implementation 'androidx.constraintlayout.widget:constraintlayout:1.1.3'
I get ERROR: Failed to resolve: androidx.constraintlayout.widget:constraintlayout:1.1.3, so I used the previous implementation directive.
Here is my XML file:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.jbiss.petminder.activities.MainActivity">
<!--<android.support.v7.widget.Toolbar-->
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/colorPrimaryDark"
android:elevation="4dp"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
<TextView
android:id="#+id/tvMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:accessibilityLiveRegion="assertive"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar"
tools:text="error message goes here"/>
<TextView
android:id="#+id/tvEmVet"
android:layout_width="wrap_content"
android:layout_height="44dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="20dp"
android:layout_marginTop="8dp"
android:text="#string/emergency_vet"
android:textColor="#android:color/holo_red_dark"
android:textSize="24sp"
app:layout_constraintStart_toEndOf="#+id/phoneCallEmVet"
app:layout_constraintTop_toBottomOf="#+id/recyclerview1"
tools:textSize="24sp"/>
<ImageView
android:id="#+id/phoneCallEmVet"
android:layout_width="37dp"
android:layout_height="44dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="8dp"
android:onClick="callEmVet"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/recyclerview1"
app:srcCompat="#android:drawable/sym_action_call"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview1"
android:layout_width="368dp"
android:layout_height="365dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/pet_name"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Running my app produces the following error:
2019-02-18 19:43:36.031 458-458/com.example.jbiss.petminder E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.jbiss.petminder, PID: 458
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.example.jbiss.petminder-i-ubC_oLu_y7-aFpiqALqg==/base.apk", zip file "/data/app/com.example.jbiss
Following the information doesn't work, for some reason. The migration has been tough but I've cleaned up a lot of issues and am now unable to find a reason why this is happening when it appears that I have done what is intended.
I solved my problem. I found that Androidx migration is a bit more involved than I had at first thought. Knowing that I had updated the labels of the ConstraintLayout elements in the XML files used in the initial screen, I used Windows GREP to search for "android.support.constraint.ConstraintLayout" throughout my project. Lo and behold I found instances that I had missed and so I updated the XML file reference to "androidx.constraintlayout.widget.ConstraintLayout".
This allowed my project to be successfully built and launch on the emulator. However, after trying to access another screen I got the same error as shown in my initial post, but for the AppBarLayout. So, I must proceed for this one as I did for ConstraintLayout and then any others.
If you are migrating, be prepared for a little more work than you had anticipated!
I was facing the same problem after migrating to androidX. Tried above solution. But, it didn't work. I added mavenCentral() in project level app gradle.
repositories {
jcenter()
maven { url 'https://maven.google.com' }
mavenCentral()
}
with following changes
dependencies {
implementation 'com.google.android.material:material:1.0.0'
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
}
updated "android.support.constraint.ConstraintLayout" xml tag with "androidx.constraintlayout.widget.ConstraintLayout"
finally it worked.
If you experience this issue on Android Studio 3.6.3 after using the Migrate to Androidx tool like I did, Here is what worked for me:
I was using androidx.constraintlayout.ConstraintLayout in my layout XML file instead of androidx.constraintlayout.widget.ConstraintLayout
The difference is one has widget before ConstraintLayout. The dependency in my app-level build.gradle was:
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
The latest at that time.

Enabling R8 causes "android.view.InflateException Error inflating class TextView" in TextView with fontFamily

I'm trying to shrink/obfuscate my release build with R8 (AS 3.3) but it's crashing trying to inflate an XML file, specifically on a TextView with a fontFamily. Removing the fontFamily attribute fixes the issue.
XML file:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/blue_linear_gradient"
tools:context=".login.LoginFragment">
<ImageView
android:id="#+id/familyIcon"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="32dp"
app:srcCompat="#drawable/auth_login_icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView <!-- This is line 20 -->
android:id="#+id/title"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:lineHeight="24dp"
android:maxWidth="168dp"
android:text="#string/login_title"
android:textAlignment="center"
android:fontFamily="#font/gotham_bold" <!-- Removing this line fixes it -->
android:textColor="#color/kineduWhite"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="#+id/authForm"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/familyIcon" />
<include
android:id="#+id/authForm"
layout="#layout/auth_form"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:maxWidth="324dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/familyIcon" />
<!-- More views... -->
</androidx.constraintlayout.widget.ConstraintLayout>
This is the stacktrace:
2019-01-17 17:37:26.496 24514-24514/? E/AndroidRuntime: FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class TextView
Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class TextView
Caused by: java.lang.NullPointerException: Attempt to read from field 'long android.content.res.XmlBlock$Parser.mParseState' on a null object reference
at android.content.res.XmlBlock$Parser.getAttributeListValue(XmlBlock.java:320)
at androidx.core.content.res.FontResourcesParserCompat.androidx.core.content.res.FontResourcesParserCompat$FamilyResourceEntry parse(org.xmlpull.v1.XmlPullParser,android.content.res.Resources)(SourceFile:1)
at androidx.core.content.res.ResourcesCompat.android.graphics.Typeface loadFont(android.content.Context,android.content.res.Resources,android.util.TypedValue,int,int,androidx.core.content.res.ResourcesCompat$FontCallback,android.os.Handler,boolean)(SourceFile:14)
at androidx.core.content.res.ResourcesCompat.android.graphics.Typeface loadFont(android.content.Context,int,android.util.TypedValue,int,androidx.core.content.res.ResourcesCompat$FontCallback,android.os.Handler,boolean)(SourceFile:3)
at androidx.core.content.res.ResourcesCompat.android.graphics.Typeface getFont(android.content.Context,int,android.util.TypedValue,int,androidx.core.content.res.ResourcesCompat$FontCallback)(SourceFile:8)
at androidx.appcompat.widget.TintTypedArray.android.graphics.Typeface getFont(int,int,androidx.core.content.res.ResourcesCompat$FontCallback)(SourceFile:8)
at androidx.appcompat.widget.AppCompatTextHelper.void updateTypefaceAndStyle(android.content.Context,androidx.appcompat.widget.TintTypedArray)(SourceFile:102)
at androidx.appcompat.widget.AppCompatTextHelper.void loadFromAttributes(android.util.AttributeSet,int)(SourceFile:59)
at androidx.appcompat.widget.AppCompatTextView.void <init>(android.content.Context,android.util.AttributeSet,int)(SourceFile:7)
at androidx.appcompat.widget.AppCompatTextView.void <init>(android.content.Context,android.util.AttributeSet)(SourceFile:2)
at androidx.appcompat.app.AppCompatViewInflater.androidx.appcompat.widget.AppCompatTextView createTextView(android.content.Context,android.util.AttributeSet)(SourceFile:1)
at androidx.appcompat.app.AppCompatViewInflater.android.view.View createView(android.view.View,java.lang.String,android.content.Context,android.util.AttributeSet,boolean,boolean,boolean,boolean)(SourceFile:30)
at androidx.appcompat.app.AppCompatDelegateImpl.void onSubDecorInstalled(android.view.ViewGroup)(SourceFile:89)
android.view.View createView(android.view.View,java.lang.String,android.content.Context,android.util.AttributeSet)
at androidx.appcompat.app.AppCompatDelegateImpl.android.view.View onCreateView(android.view.View,java.lang.String,android.content.Context,android.util.AttributeSet)(SourceFile:1)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:189)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at com.company.auth.login.LoginFragment.android.view.View onCreateView(android.view.LayoutInflater,android.view.ViewGroup,android.os.Bundle)(SourceFile:7)
My font lives in a separate library module.
Font family xml file "res/font/gotham-bold.xml" in :core
<font-family xmlns:app="http://schemas.android.com/apk/res-auto">
<font
app:fontStyle="normal"
app:fontWeight="400"
app:font="#font/gotham_rnd_bold"/>
<font
app:fontStyle="italic"
app:fontWeight="400"
app:font="#font/gotham_rnd_bold_italic"/>
</font-family>
And the actual font "gotham_rnd_bold.otf" is also in this :core module under "res/font/
I post here the reason why provided by R8 developers (from your issue) for better indexing and reference.
This happens because you are including program classes in your app
that is already in the Android framework. The Proguard configuration
rule -dontwarn org.xmlpull.v1.** explicitly disables these warnings
from the compiler.
Ideally, you should not include any classes in your app that is also
in the Android framework. You should be able to identify the
dependency that includes org.xmlpull.* and then exclude that module
from the dependency. It seems that others have successfully done this,
see for example https://stackoverflow.com/a/34486112. If you manage to
do this, then you shouldn't get any warnings even if you remove the
rule -dontwarn org.xmlpull.v1.**.
Alternatively, you can use the rule -keep class org.xmlpull.** { *;}.
This trick appears to be used by others
(https://github.com/search?q=org.xmlpull.v1+extension=pro&type=Code),
but it can be error-prone since your version of org.xmlpull.* may be
different from the one in the Android framework.
Note that we are working on changing the behavior of R8 such that it
deals with duplicate classes in a way such that Android framework
classes always take precedence of program classes (b/120884788). In
principle, none of the above changes should be needed with that fix.
You can set custom font programatically such as;
customText.typeface = ResourcesCompat.getFont(this,
R.font.your_font)

Error inflating class android.support.design.widget.FloatingActionButton

My app crashed because
Error inflating class android.support.design.widget.FloatingActionButton
This is my code in the XML
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="#drawable/icon_right"
app:backgroundTint="#color/green"
android:onClick="previewphoto"
app:layout_anchorGravity="bottom|right|end" />
and here is my gradle
compile 'com.android.support:appcompat-v7:23.4.0' // appcompat library
compile 'com.android.support:design:23.4.0'
my logcat
FATAL EXCEPTION: main Process: com.cyanlabsid.cetakphoto, PID: 15298
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.cyanlabsid.cetakphoto/com.cyanlabsid.cetakphoto.PhotoPicker}:
android.view.InflateException: Binary XML file line #76: Binary XML
file line #76: Error inflating class
android.support.design.widget.FloatingActionButton at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2423)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:153) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:102) at
android.os.Looper.loop(Looper.java:148) at
android.app.ActivityThread.main(ActivityThread.java:5441) at
java.lang.reflect.Method.invoke(Native Method) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628) Caused
by: android.view.InflateException: Binary XML file line #76: Binary
XML file line #76: Error inflating class
android.support.design.widget.FloatingActionButton at
android.view.LayoutInflater.inflate(LayoutInflater.java:543) at
android.view.LayoutInflater.inflate(LayoutInflater.java:427) at
android.view.LayoutInflater.inflate(LayoutInflater.java:374) at
android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at
android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.cyanlabsid.cetakphoto.PhotoPicker.onCreate(PhotoPicker.java:74)
at android.app.Activity.performCreate(Activity.java:6303) at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483) 
at android.app.ActivityThread.access$900(ActivityThread.java:153)  at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) 
at android.os.Handler.dispatchMessage(Handler.java:102)  at
android.os.Looper.loop(Looper.java:148)  at
android.app.ActivityThread.main(ActivityThread.java:5441)  at
java.lang.reflect.Method.invoke(Native Method)  at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
Can somebody tell my fault?
Use
app:backgroundTint
in stead of
android:backgroundTint
Hope it will work.
Because android:backgroundTint doesn't work below android API 21, so you need to use app:backgroundTint instead.
Tried your code, the problem is with the 23.4.0 library.
Upgrade to 24.+ , there's no error in that lib.
For example :
implementation 'com.android.support:appcompat-v7:24.2.1' // appcompat library
implementation 'com.android.support:design:24.2.1'
You need to change the compile version to 24 too.
compileSdkVersion 24
Below API level 21 app versions not support for the
app:backgroundTint="#color/green"
or you can use this library for achieve more material design widgets.
https://github.com/navasmdc/MaterialDesignLibrary
happy coding...
You need to add
android:theme="#style/Theme.AppCompat"
in the XML_Layout file in which you are using FloatingActionButton...
I had the same problem
I faced the same issue with Pre-Lolipop version and to resolve it, I just changed "android:src" to "app:srcCompat" & it worked for me.
To make compatibility with older version and if you're using a Vector graphics (as drawable assets) you should use:
app:srcCompat="#drawable/you_graphics"
instead of:
android:src="#drawable/your_graphics"
I am using:
classpath 'com.android.tools.build:gradle:3.3.2'
and
distributionUrl=https://services.gradle.org/distributions/gradle-4.10.1-all.zip
I changed my XML to:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:focusable="true"
app:srcCompat="#drawable/mapit"
app:layout_anchor="#id/foundit_imageView"
app:layout_anchorGravity="bottom|right|end" />
and everything built and ran correctly.
I hope this helps
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="#drawable/ic_add_foreground"
android:layout_margin="16dp" />
Use this
<com.google.android.material.floatingactionbutton.FloatingActionButton>
instead of
<android.support.design.widget.FloatingActionButton>
Make sure the library from which you declared the FloatingActionButton in the activity is the same as the one used for the layout markup
For example have
import com.google.android.material.floatingactionbutton.FloatingActionButton; in the activity and
com.google.android.material.floatingactionbutton.FloatingActionButton as the tag for the layout
I was using Material Design for my ExtendedFloatingActionButton and when using API 24 it would crash the app.
I tried updating my gradle dependencies to the latest version:
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0-alpha02'
but I had no luck with that either. My solution was adding android:theme="" even though I had set a style it would still crash so I set the theme to the same as the style and it worked perfectly.
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="#+id/btn_one"
android:theme="#style/"
style="#style/"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/text"
android:text="#string/text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Add in
build.gradle(:app)
implementation 'com.google.android.material:material:1.2.0'
Use this in your XML
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="#drawable/icon_right"
app:backgroundTint="#color/green"
android:onClick="previewphoto"
app:layout_anchorGravity="bottom|right|end" />
use this code it will be work better ;
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="16dp"
app:backgroundTint="#f9fcfc"
android:src="#drawable/chat_float"
tools:targetApi="lollipop" />

View Background problems

This happened a couple of days ago. Still cannot find the way to fix it.
Here is a simple test project.
http://s000.tinyupload.com/index.php?file_id=03903482111052488979
Pretty simple layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
>
<EditText
android:id="#+id/editUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ems="10"
android:hint="#string/input_hint_email"
android:inputType="textEmailAddress"
/>
<EditText
android:id="#+id/editPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/edit_hint_password"
android:inputType="textPassword"
android:layout_gravity="center"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Enter"
/>
</LinearLayout>
Gradle important parts:
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.2.1'
}
Ple-lollipop devices (genymotion and real devices)
The background (pressed, sometimes normal) looks like something wrong with 9-patch file. Some of affected views - item in navigation view, menu item, edittext
edittext - https://gyazo.com/71f13003a46ff596514e475a72f924b7
pressed menu item - https://gyazo.com/7a5d9db29e17524e353f10a18562786e
Lollipop until 5.1
Crashes on startup (stop crashing on appcompat 23.1.1 and lower)
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ww.aeli.wtf.MainActivity}: android.view.InflateException:
Binary XML file line #11: Error inflating class EditText
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class EditText at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-v21/abc_edit_text_material.xml from drawable resource ID #0x7f020015 at android.content.res.Resources.loadDrawableForCookie(Resources.java:2428)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #24: <nine-patch> requires a valid 9-patch source image at android.graphics.drawable.NinePatchDrawable.updateStateFromTypedArray(NinePatchDrawable.java:445)
Lollipop 5.1 and marshmallow
Everything works fine
What have i tried
Problem also was reproduced on other developer machine.
Downgrading appcompat till the version 23.0.0. Lollipop do not crashes on 23.1.1 and lower, but background problem persists.
Disabling vector support (the main 23.2.0 feature, that theoretically could affect).
Similar recent problems - https://code.google.com/p/android/issues/detail?id=210467 (the discussion went on the strange way), https://github.com/afollestad/material-dialogs/issues/1081, https://code.google.com/p/android/issues/detail?id=210547
older one:
https://code.google.com/p/android/issues/detail?id=198457
Well, i find the way to "fix" all the issues as always just after posting a question.
Downgrading the gradle version from 2.2.0-alpha1 to 2.1.+ will solve all the problems.
And again note to myself - never use "+" in library versions.

Categories

Resources