android.support.design.chip.Chip - android

I'm face to a problem with chip component on android.
I try to implemente a chip like this:
<android.support.design.chip.Chip
android:id="#+id/tags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello world"/>
But when I launch my app I have this error:
android.view.InflateException: Binary XML file line #59: Binary XML file line #59: Error inflating class
android.support.design.chip.Chip
Caused by: android.view.InflateException: Binary XML file line #59:
Error inflating class android.support.design.chip.Chip
Caused by: java.lang.IllegalArgumentException: The style on this
component requires your app theme to be Theme.AppCompat (or a
descendant).
My style is already an AppCompact.

You need to use app theme to Theme.MaterialComponents.Light.Bridge inspite of AppCompat if you want to use android.support.design.chip.Chip.
Reason:
Chip component relies on new MaterialComponents theme, so is why the
crash occurs. Bridge theme here are treated as AppCompat but
provides new MaterialComponents theme when needed.

Related

AppCompatSpinner throwing InflateException on only few devices

Two days i was stuck with IllegalArgument Exception(given the crash log below) while clicking on the custom AppCompatSpinner.
This issue is not happening in all devices, only few devices(Samsung, Oneplus) affected.
App themes are listed below for all the api version
parent="Theme.AppCompat.NoActionBar"
v23 theme:
parent="Theme.AppCompat.Light.NoActionBar"
v21 theme :
parent="Theme.MaterialComponents.DayNight.NoActionBar"
My crash log:
E/AndroidRuntime: FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #95: Binary XML file line #37: Error inflating class Button
Caused by: android.view.InflateException: Binary XML file line #37: Error inflating class Button
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
Please give some insights to fix this issue. Found some solutions in stackoverflow & other sites but nothing helped me to fix the issue
If you want to use Material UI elements, then
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> should be changed to <style name="AppTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">.
As the error itself is saying, your app theme must be a child of MaterialTheme or any child of the same.
How to build a material theme

Material chip crashing app. Cannot inflate xml

My app crashes when trying to inflate the com.google.android.material.chip.Chipclass.
The dependency i am using is implementation 'com.google.android.material:material:1.0.0'
Here is my XML code
<com.google.android.material.chip.Chip
android:id="#+id/chipActive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:chipCornerRadius="5dp"
android:backgroundTint="#color/primaryColor"
android:textColor="#color/primaryTextColor"
android:textAlignment="center"
android:fontFamily="#font/roboto_regular"
android:layout_marginStart="10dp"
android:text="Active"/>
The error I get is
android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class com.google.android.material.chip.Chip
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
I found a question similar to mine on another thread but there was no solution there that was helpful to me. If anyone has any suggestions on how to fix this issue please help me :D
I found the solution just after posting this question. I updated the dependency to implementation 'com.google.android.material:material:1.1.0-alpha02' and now it works fine.
Use Theme <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
Put this code in the chip
android:theme="#style/Theme.MaterialComponents.Light"

Exception when trying to use a <vector> as src for an ImageView

I have in one of my layout files.
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
app:srcCompat="#drawable/ic_app"
android:layout_gravity="center"/>
My ic_app.xml is located in flavor/res/drawable. I notice that if I move the icon into main/res/drawable. Everything is working again!
The drawable ic_app is an XML. But for some reason, my android API-23 phone would crash whenever this activity is launched that contains this ImageView. Saying that the resource is not found.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.app.android.view.activity.login.WelcomeActivity}: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class ImageView
Caused by: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class ImageView
Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class ImageView
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_app.xml from drawable resource ID #0x7f02029e
I have never seen this happening before. What could the cause be?
The same app runs correctly in an API-19 device.
If you are using vector drawables, use
app:srcCompat="#drawable/ic_app"
instead of
android:src="#drawable/ic_app"
Here is a Good Read
Try to use app:srcCompat="#drawable/ic_app" instead of android:src="#drawable/ic_app".
I've found this
Firstly, when using AppCompat with ImageView (or subclasses such as ImageButton and FloatingActionButton), you’ll be able to use the new app:srcCompat attribute to reference vector drawables (as well as any other drawable available to android:src):
On this Blog

android.view.InflateException:Binary XML file line #18:Error inflating class android.support.design.widget.NavigationView

java.lang.RuntimeException: Unable to start activity ComponentInfo{cab.app.book/com.epbit.ccv3.MainActivity}: android.view.InflateException: Binary XML file line #18: Error inflating class android
support.design.widget.NavigationView.
Added design and appcompat library and Tried in all the ways, but unable to solve the issue.
Please help
Your layout's file has an error in line 18.

Android Error inflating class TextInputLayout

I'm trying to use TextInputLayout in my XML, and I'm meeting this error :
java.lang.RuntimeException: Unable to start activity ComponentInfo{fr.jechange.moncompte/fr.jechange.moncompte.SignUpActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.design.widget.TextInputLayout
[...]
Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.design.widget.TextInputLayout
[...]
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/design/R$styleable;
I've imported the design library, and the support-v7-appcompat library. And I'm using the Theme.AppCompat.Light.NoActionBar theme.
The XML in which I'm using the Text Input Layout contains just something like that:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:res="http://schemas.android.com/apk/res-auto"
style="#style/matchParent">
<android.support.design.widget.TextInputLayout
android:id="#+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
if you are calling layout(containg TextInputLayout) from activity then
nothing just use YouActivityClassName.this in place of getApplicationcontext or YourApplicationClassName.getcontext() or other where you are passing context
I had the same issue fixed here.
Make sure you don't have any other support library import v4 and v7. You can use only the design-support library. Also you should make sure your theme "matchParent" inherit from Theme.AppCompat for all the platform you trying to run.
My issue was only on Lollipop because of the values-21/style.xml.
Hope it will help.

Categories

Resources