I have there is no resources error in my xml file - android

I have an Android xml file that added to create a splash, for this splash I uploaded a image and set xxhdpı, xhddi, mdpı, hdpı formats from nine patch then I added each one to each format (I mean xxhdpı to xxhdpı format and mdpı to mdpı format folder under resources) then it gives an error
no resources found the given name(at backround with value '#drawable tesbihsplashh.9.png'

Set Background image like:
android:background="#drawable/tesbihsplashh"
Make sure tesbihsplashh.png image avialable into your drawable folder.

Related

Android add multiple pictures to drawable res folder

I want to add over 200 icons (smaller than 50x50px) to the drawable resource. The drag and drop does not work for me. Using New Image asset permits to upload only a single photo.
here is my project resource folder structure:
After adding pictures to the drawable folder, I was unable to get the images. Here is my code
Resources res = activity.getResources();
String mDrawableName = user.getNat().toLowerCase() + ".png";
int resourceId = res.getIdentifier(mDrawableName , "drawable", activity.getPackageName());
Drawable drawable = res.getDrawable(resourceId);
countryIcon.setImageDrawable(drawable );
Why I cannot find images in drawables?
Where should I copy the photos in the file explorer/finder? I have drawable folder and mipmap folders for different dimensions
Is it a good idea to have 200 pngs inside the project? (I have different codes like 33483477, and for every code I have a image which I need to display)
Just copy them directly to your project under <your project>/<your module>/src/main/res/drawable[-qualifier].
Without other details of your project, I can't say specifically into which drawable resource folder these should live (-hdpi, -nodpi?).
Is it a good idea to have 200 pngs inside the project?
It depends on the size. There is an APK size limit of 100MiB. If bigger, you can stage expansion files, which are essentially opaque archives of data.
Other than that, you should consider the usage pattern of the images. Are all of the images viewed, always, by all users? Point being, if the user has to download all of them eventually, bundling them all in the APK is probably okay. If they only use a few of them, making them download them all (in your APK) is a waste of their bandwidth.
Staging the images on a server and downloading them on demand adds a little complexity to your app, but it's a well-established pattern.
I use below code to get drawables. hope it will work for you. no need of .png file extention. thats what you did wrong. Also use getResources() method before calling getIdentifier.
String mDrawableName = user.getNat().toLowerCase(); //image or icon name. not need extention .png
int resourceId = getResources().getIdentifier(mDrawableName, "drawable", getPackageName()); // or use context.getResources(). If you use fragments, use getActivity().
Drawable drawable = getResources().getDrawable(resourceId);
countryIcon.setImageDrawable(drawable );

Error while loading gif image source

I tried executing the following line to load gif image, programatically.
gifInputStream = context.getResources().openRawResource(R.drawable.image);
But, studio used to indicate an error near "R.drawable.image".
I found a solution, or rather hack around to my issue. I just added "+" symbol. So, the line looks like this now...
gifInputStream = context.getResources().openRawResource(+R.drawable.image);
AndroidStudio doesn't show any error now.
it required raw file not drawable.
Please create res/raw/ directory and move your file in the raw directory.
after then:-
context.getResources().openRawResource(R.raw.yourfilename)

VectorDrawable createFromStream does not seem to work

I am trying to load vector drawables from the assets.
It works fine when I use png files:
final String name = "image.png";
final InputStream stream = context.getAssets().open(name);
drawable = Drawable.createFromStream(stream, name);
stream.close();
I tried using VectorDrawable.createFromStream() and VectorDrawableCompat.createFromStream() but both always return null.
When I add the vector drawable to the drawbles resources it can be loaded without a problem.
I also tried using the binary xml file which gets created when adding the vector file to the drawables resources.
I use API level 24 and Support libs 24.2.0 with Android 5.1.1 to test this. It should work on Android 4.2 and later.
Does anyone know how to fix this?
This issue could relate to this one:
Load a vector drawable into imageview from sd card
After looking at the Android source code I found a solution.
The method createFromStream does not seem to support vector drawables. Because it uses a BitmapFactory.
but we can load them as xml resource:
final XmlResourceParser parser = context.getAssets().openXmlResourceParser("assets/folder/image.xml");
drawable = VectorDrawableCompat.createFromXml(context.getResources(), parser);
The image.xml musst be a precompiled binary xml file.
You can extract them out of the generated apk file when you add the vector drawable to the drawable resources.
The problem with this approach is, that it needs Android 5. But I need a working code for Android 4.2. Anyone an idea?

Android openRawResource() not working for a drawable

I'm trying to create an input stream by doing this
InputStream is = (InputStream) getResources().openRawResource(R.drawable.image1);
but I'm met with the error "Expected resource of type raw" with respect to my drawable file (R.drawable.image1). image1 is a png and in my res/drawable folder.
Any ideas???
#Broatian I don't currently have a res/raw folder. I found an alternative solution:
is = context.getResources().openRawResource(+ R.drawable.image1);
The + shows additional folders. Thanks for the help!
If you want to open your png with this method then you have to put it in the res/raw folder. Then you'll be able to access the png using R.raw.image1.
Another alternative is to keep it in the drawable folder and then convert the drawable to a InputStream. See How to read drawable bits as InputStream
I assume you know how to get the drawable otherwise look at the Resources documentation.
It is because They are expecting a raw type resource and you are passing a drawable type one.
make a raw folder in the res folder and then put your image in the raw folder.

Failed to convert #drawable/ into a drawable

I have added an image to my Android project which I want to use in the UI. I have added the file my-image.png to the drawable directory (to all 4 drawable directories created with the project), and added the ImageView to the layout:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/textView"
android:layout_marginBottom="63dp"
android:src="#drawable/my-image" />
The problem is that I get the following error:
Rendering Problems
Failed to convert #drawable/my-image into a drawable
This is the capture:
Additionaly, if I try to compile the project, I get the following error:
Gradle: Execution failed for task ':MyProject:processDebugResources'.
Why do I get these errors and how can I solve it? Am I missing something? I've just started Android development.
Gradle: Execution failed for task ':MyProject:processDebugResources'.
because you have naming convention error in Resources
file name: must contain only [a-z0-9_.]
Rename file name to my_image
Rename this drawable #drawable/my-image to #drawable/my_image
Try using underscore and small characters in file name, for example
my_image.png
Try To use only abc...xyz and 0123...9, dont use -, instead use _(underscore).
Use my_name instead of my-name, because Hyphens(-) have a special meaning in coding, so it cant be use literally with strings.
If the naming convention is correct try:
Open up resources dialog and see if image png preview is displayed.
Select image in design view > Go to properties > Click the ellipsis button > Drawable > Search for your png image and click on it.
If the preview is not displayed cancel out of resources, and try resaving the image again in png format.
This example uses photoshop CS2. Open image in photoshop and select Files > Save For Web > Click Save. (Do not use File > Save As)
It worked for me you should not include special characters only alphabets

Categories

Resources