View Background problems - android

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.

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.

Inflating class android.support.v4.widget.SwipeRefreshLayout

I am trying to implement SwipeRefreshLayout in fragments. It is looking created correctly, but I continue to get the errors:
Caused by: android.view.InflateException: Binary XML file line #2:
Binary XML file line #2: Error inflating class
android.support.v4.widget.SwipeRefreshLayout
Caused by: android.view.InflateException: Binary XML file line #2:
Error inflating class android.support.v4.widget.SwipeRefreshLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class
"android.support.v4.widget.SwipeRefreshLayout" on path:
DexPathList[[zip file "/data/app/com.weather.rainy-
2/base.apk"],nativeLibraryDirectories=[/data/app/com.weather.rainy-
2/lib/x86, /system/lib, /vendor/lib]]
I really don't have any idea what is causing this.
My fragment layout for implementing the SwipeRefreshLayout:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/swipeToRefresh4Maps"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/topRL4Maps"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_gradient_purple"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="64dp"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingBottom="64dp"
tools:context="com.weather.rainy.ui.MapsActivity">
<TextView
android:id="#+id/yourLocationLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="#+string/your_location"
android:textColor="#android:color/white"
android:textSize="24sp" />
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/addressValueTextView"
android:layout_alignBottom="#+id/addressValueTextView"
android:layout_below="#+id/yourLocationLabelTextView"
android:layout_centerHorizontal="true"
android:layout_margin="15dp"
tools:context="com.weather.rainy.ui.MapsActivity" />
<TextView
android:id="#+id/addressValueTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/map"
android:layout_alignEnd="#+id/map"
android:layout_alignParentStart="false"
android:layout_alignParentBottom="true"
android:text="#+string/..."
android:textColor="#aaffffff"
android:textSize="18sp" />
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
And, my fragment class for calling the SwipeRefreshLayout:
//Code for Swipe Refresh
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeToRefresh4Maps);
mSwipeRefreshLayout.setColorSchemeResources(R.color.Red, R.color.Orange, R.color.Blue, R.color.Green);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
Log.v(TAG, "************** MAPS - SWIPE REFRESH EVENT TRIGGERED!!!!!");
findLocation();
}
});
I really don't have any clue, what is the wrong. Any help is greatly appreciated.
Because you are using AndroidX, your XML is referencing the wrong version of SwipeRefreshLayout
Change in your XML from android.support.v4.widget.SwipeRefreshLayout to androidx.swiperefreshlayout.widget.SwipeRefreshLayout
I was stuck on the SwipeRefreshLayout using AndroidX
I was not able to get Reference of SwipeRefreshLayout in AndroidX
So I added implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
dependency in app level gradle file.
So in my case solution is,
Add the dependency in app level build.gradle file
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
This issue seems to happen when migrating to AndroidX as there are many build artifact to be changed when Migrating to AndroidX.
Solution 1: Do it manually
For exemple:
android.support.v4.widget.SwipeRefreshLayout changed to => androidx.swiperefreshlayout.widget.SwipeRefreshLayout
You must update all the build artifact listed in Migrating to AndroidX
Solution 2: Automate on Android Studio 3.2+
As suggested in this same link, you could automate this process by selecting Refactor > Migrate to AndroidX from the menu bar.
ADDITIONAL INFO - The errors I had:
Error inflating class android.support.constraint.ConstraintLayout
element WebView is not allowed here
Gradle needs to new dependency which is AndroidX:
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
If you use SwipeRefreshLayout in Java class, you can see this line:
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
In you XML file, you should use the tags of SwipeRefreshLayout:
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout

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)

Missing resources for Android CardView library

I'm using CardView in my project and I'm getting an error on older devices:
E android.view.InflateException: Binary XML file line #25: Error inflating class android.support.v7.widget.CardView
E at android.view.LayoutInflater.createView(LayoutInflater.java:518)
E at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
E at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
E at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
E at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
E at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
Seems similar to a few questions on SO such as this one
My problem is that the solution for that questions feels very hacky and that's understandable as the answer was given last year when Lollipop just entered the public preview. Have things changed since? How do I get the resources?
I've tried a few things such as importing .aar as a module but nothing seems to work. I've followed the official documentation on how to add support libraries (https://developer.android.com/tools/support-library/setup.html#libs-with-res) but that didn't work. Also according to that link - there doesn't seem to be any difference between adding libraries with and without resources for Android Studio?
My app build.gradle includes the following dependencies:
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:cardview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
CardView layout is used here
<android.support.v7.widget.CardView
xmlns:card="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
card:cardCornerRadius="6dp"
card:cardUseCompatPadding="true"
tools:ignore="NewApi">
EDIT: the problem noticed on Samsung S2 2.3 - API 19+ works fine
?android:attr/selectableItemBackground is platform related, use it without android: prefix to refer to AppCompat's attribute.

Categories

Resources