NavigationDrawer ResourcesNotFound - android

I've made some custom icons in inkscape, saved as svg and transform the svg to the vector drawable. The drawable i saved under the drawable-v21 folder. After this i add the new vector to the navigation drawer menu. After this i open the layout which include the menu and i see my custom icon, everything fine.
But if i start the app i get a android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView and if i looking through the exception i see at the end a Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f02004d.
I have no idea why, because i see the icon in the layout preview.
Any ideas?
What i have done: gradle sync, invalidate and restart android studio.
Thank's in advance.

It's running on version 19
Since you are putting your drawable in drawable-v21 folder it means it is intended for API 21 and up, as as you are running on API 19 there's no drawable available, hence the Exception. So you must either provide alternative drawable for other APIs or do not access this drawable when app is running on pre 21 API
mandatory read - docs on providing resources.

For those they running in the same problem, you must search for a file calling drawables.xml in this file android define the fallback/alternative image. It look's like this:
<item name="custom_image_xml" type="drawable">#drawable/custom_image</item>
and in the navigationdrawer menu:
<item
android:id="#+id/nav_overview"
android:icon="#drawable/custom_image_xml"
android:title="#string/action.overview" />
Note: That's "_xml" suffix is only used to explain and illustrate the mapping in the drawables.xml

Related

app launcher icon changed to default icon on Oreo

I have created an Android app with its own launcher icon. It worked well with Nougat. But with Oreo, my icon is replaced by the default Android icon.
I have defined ic_launcher.png and ic_launcher_round.png in the mipmap resources for several densities.
My manifest contains the following line:
android:roundIcon="#mipmap/ic_launcher_round"
What should I do to make my own icon appear on Oreo ?
For API 26+ default Android application template defines another icon resource folder
mipmap-anydpi-v26
That folder (usually) contains two xml files ic_launcher and ic_launcher_round that match icon resources declared in manifest for API 26+
Content of those files looks like following:
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="#drawable/ic_launcher_background"/>
<foreground android:drawable="#drawable/ic_launcher_foreground"/>
</adaptive-icon>
In order to have your icon you also need to change all drawables (in all density buckets) listed there - namely ic_launcher_background and ic_launcher_foreground
Or you can just delete that folder, in which case android will fallback to using your png icons, but they will not appear as-is and will be commonly drawn on top of white background.
You can read more at: Adaptive icons
Best solution is delete mipmap-anydpi-v26 folder then app will take default icon. In android studio Project mode go to this package
res/mipmap-anydpi-v26
delete it and rebuild and Run Project.
My solution:
check res/mipmap-anydpi-v26 folder, then you will see ic_launcher.xml and ic_launcher_round.xml files
edit these xml files to point to the actual png file you want to use:
If such png file is not available inside the drawable folder, add it.
That solves the issue.

Use SVG in CompoundDrawable with SDK<21

I was using SVG's in my Android application as src of my ImageView, using appSrc attribute in order to give compatibility backwards (SDK<21).
But now I have tried to use them in my TextView Compound Drawables (drawableXXX attributes) and I get multiple errors when I use a device with KitKat (The same errores that I had when I used android:src instead of app:srcCompat).
Caused by: android.view.InflateException: Binary XML file line #261: Error inflating class
Is there anyone who know a way to use them in Compound Drawables?
as of now you cannot add a VectorDrawable from xml attributes, that functionality is only limited to app:srcCompat more on this in the android developers blog post
However you may do it programmatically using VectorDrawableCompat.create(Resources, int, Theme) and then add it as a compound drawable to the TextView using TextView#setCompoundDrawables
see :
developer.android.com/reference/android/support/graphics/drawable/VectorDrawableCompat.html
developer.android.com/reference/android/widget/TextView.html
I had the same issue and i found only two options:
1) set your drawable programmatically or create a custom view
2) remove "vectorDrawables.useSupportLibrary = true" from your build.gradle
This will cause Android Studio to generate PNGs at compile time for apps with a minSdkVersion less than API 21 while using your vectors on API 21+ devices, allowing you to keep the same code at the cost of additional APK size.
As is described in this article, you can create a little hack for this issue. Just create layer-list drawable file(ic_working_image.xml) like this:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_your_image_name"/>
</layer-list>
And then just use the new drawable on TextView as before with drawableXXX attributes.

Android Studio resource dialogue is not showing my project drawables

I have encountered the following issue in Android Studio: when I select the "..." to specify the source drawable file for an ImageView, in the Project tab I don't see the project drawables, even if they do appear into the drawable folder on the left pane, but instead a long list of (I guess) system drawables (whose name is starting with "abc_") and no trace of the custom files I have successfully pasted into the project drawable folders.
If I try to write manually a reference to the correct resource in XML (android:src="#drawable/main_title"), I get the following error popup:
Rendering Problems Couldn't resolve resource #drawable/main_title. Failed to convert #drawable/main_title into a drawable.
Does anybody have any idea of what's happened? Thank you in advance.
You're trying to put in android:src a string, not a Drawable. If you want to apply drawable to your ImageView src you should use somthing like this:
android:src="#drawable/your_image_drawable"
I just found my own mistake: I pasted the drawable files inside the drawable folder, while they must reside inside the res folder. Now it works.
Thanks for your replies.

Xamarin Colors Causing Build Errors

I have an android application built with Xamarin Studio. I added a file named colors.xml to the Resources/values folder. The contents were:
<resources>
<color name="ViewBackgroundColor">#ffffff</color>
</resources>
To that, I was following this approach to define and use it; however, I was trying to apply it to the view's root element (found that resource elsewhere on SO, don't have exact link). So I applied it to the view by adding android:background="#color/ViewBackgroundColor" attribute to the root element. However, this generates a build error that #color/ViewBackgroundColor isn't a value. is anybody else having this issue and is there a resolution?
To reference that color, you must use all lowercase letters.
So
android:background="#color/viewbackgroundcolor"
This is because the Xamarin tools lowercases all names to be compliant with the rules Android has for resource names.
Is also important to set "Build Action" (with mouse right button on file color.xml) as AndroidResource.

Error Parsing XML for android:drawable

Hi
I am facing a problem
I want my application to pick up resources from the framework. Here is my code snippet of an xml.
For this to be achieved following changes were made in attrs.xml
and themes.xml at the framework level
#android:drawable/btn_minus_ss
The drawable btn_minus_ss.png is added to drawable-hdpi folder at the location framework/base/core/res/res/drawable-hdpi
Whenever I open the application, it crashes.
I get the following error in logs
ERROR/AndroidRuntime(3701): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #5: tag requires a 'drawable' attribute or child tag defining a drawable
However, when I use this
android:background="?android:attr/theme_btn_minus_ss"
I don't get any error. I want to use
android:drawable
What is the cause and how can this problem be solved.
Thanks & Regards
Aviral
The error
ERROR/AndroidRuntime(3701): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #5: tag requires a 'drawable' attribute or child tag defining a drawable
has to do with the format of your xml, you are setting something like
<item android:background="#foo-value-here" />
What the error is telling you is that it should be like this
<item android:drawable="#foo-value-here" />
i think i had the same problem, it seems to be a bug in the android eclipse-plugin. the solution is the same as for this question (close eclipse and restart it): android include tag - invalid layout reference
Also make android:drawable the first attribute of item tag - it worked for me.

Categories

Resources