Android Studio resource dialogue is not showing my project drawables - android

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.

Related

Android Studio layer-list render

After wrote layer-list I got some error, refresh it but not working.
This is the image of error I got when after place this layer-list.
May be your xml file is in layout folder.
Move your xml file to drawable folder. And check it.
Hope this may help.
The above solution worked. but why won't place drawbale folder? isn't it a layout?

I hava a custom resource file which path is :app/values/defaults.xml in my app

I have defined a custom resource file which path is :app/res/values/defaults.xml in my app,but when i use the resources in other files,the IDE show me the error like the screenshot below.I have no idea how to solve this problem.
android studio show me the error like this
The error tell you that your color cpb_default_color its not create in values/color you must create first this variable in values/colors like this
<color name="cpb_default_color">#yourHexColor</color>
Hope to help!
You should place all your colors in colors.xml

create shape xml file in drawable folder in android studio

I am using Android studio 1.2.2 and need to know how to create a new shape file in drawable folder. I have already done the same in Eclipse but unable to do so in the android studio 1.2.2
follow these steps
create a drawable folder in res directory.(if not present)
right click on drawable folder> New > Drawable resource file
Give your file a name and change the root element to shape.
(its selector by default)
now you are good to go.
I was confused by the post from Anirudh when he said to change the root element to shape. But here is full demo.
Basically, the shape element is not provided by drawable resource file list by default. So just create one and then change the root xml element to shape, manually.
Right Click On drawable folder
Select New -> XML -> Layout File
Type Root Element shape

Android imageView id not showing

I have an imageView in my main.xml file, that isn't setup with a source initially. I want to be able to dynamically change the image resource within the code. so lets so i have my imageView setup like this:
<ImageView
android:id="#+id/countryImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/CountryImageContent"/>
So i try to access within my code like this:
ImageView img = (ImageView) findViewById(R.id.countryImage);
The problem is here. Eclipse is giving me an error saying that "countryImage cannot be resolved or is not a field". A quick peek into my R.java file is showing me that the imageView isn't actually in there. Why is this happening? Thanks.
look into your drawable and layout if there is any error
if not try cleaning your project
Go to Project > clean > select your project
if not then look into your imports for
your.packagename.R remove it
Project -> Clean.
That is the only solution to this.
Also make sure that among your import statements, you do not have this : import android.R
Check this link for a detailed procedure.
Note : I am assuming that there are no errors in your layout and drawable files, as errors in them may also lead to this problem.
make sure all resource files have only lowercase letters , numbers and the underscore character ("_") .
only if there are no errors in creating the R file (in the "gen" folder) , you can use the id of it.
I think it is the problem to giving the name of #string
Please Remove all UpperCase Character from #string/CountryImageContent and replace it with small character.
R.java file doesn't support any Uppercase character. It gives the same error when you declare the file name of any resources Like :- Image, XML, #string, etc...
Just rename CountryImageContent with country_image_content. it will work perfect.
Another option to try in this case is: File --> Invalidate Caches / Restart...

how to create new android xml file in drawable folder that does not have Drawable resource

this might sound silly. i am trying to do tab layout for android.
there is a part where i need to create a drawable folder and have android xml file in that particular folder.
i have looked into all the tutorial and youtube for this. The tutorial shows create a new android xml file and choose Drawable for the type of the resources.
in my case, i cannot create new android xml file with Drawable as the type of resources as Drawable does not exist. Below shows the interface.
is there anyway can help me with this? i also tried to add the resource manually but it wont work.
if i am creating a new android xml file with other resource type and force it to put in drawable folder, the application crash.
1. Go to your project explorer which should be on the left side of your eclipse IDE.
2. Right click the res folder of your project
3. Click new, then folder
4. Name that folder drawable
5. Right click your new drawable folder, click new
6. Search for XML File in the XML folder
7. ENJOY :)
I'm not sure if i understand exactly what you mean, Is this what you want to do? If so then the steps provided is how to do so, if you need me to clarify let me know.
Do the following,
your project -> new -> Folder -> write drawable in the text box -> finish
So, drawable folder is now created in res folder.
Then,
drawable -> new -> File -> enter the name of the xml file you want to create (ex. test.xml)
OR
drawable -> new -> Android XML File -> enter the name of the xml file you want to create (ex. test)
Now you can see there is a .xml file in your drawable folder. Now you do whatever you like to do with this .xml file.
#Sara if you have successfully created your extra "drawable" folder, right click on the new "drawable" folder and go to new Android XML File, just name the new xml file and finish next.

Categories

Resources