i want have an image and i want to set it as a background of android list view
i have used android:background="drawable/image" but nothing happened
can any one guide me how to achieve this?
any help would be appricated.
Perhops
android:background="#drawable/image"
noticing the #
Also make sure your project's res/drawable folder contains a valid image file called image.jpg or image.png.
Adding to Jim, clean or re-open the project to ensure your newly added image file gets reflected in the /res/drawable folder
Related
This is my project folder, when i adding first image then it not show any error but after adding the 2nd and 3rd image it show the red lines.
I don't know where i do mistake, if anyone knows then please help me.
In Android Studio, click on View > Tool Windows > Resource Manager in the menus or click on the Resource Manager tab to the left of the Project window.
Click the + below Resource Manager, and select Import Drawables. This opens a file browser.
Make sure the name of the image you are trying to add does not resemble some keyword. I was trying to add an image in drawable with name "try". When i made it "tried" error went away. So, name your image != any keyword.
FOR YOUR CASE IN PARTICULAR:
Try invalidating cache and restarting it. Moreover, also check if the problem persists only with these two images or others too.
Names should be in lowercase.
Therefore never use names with uppercase letters in it
try removing numerals and keep a meaningful name. Also ensure that the names are in lower case
drawable folder is wrong place for png files.
In drawable are stored xml files
All png files should be stored in mipmap folders
If you want have only one png for all resolutions, store it in mipmap-anydpi
I found the problem.
Add the same image to the default drawable folder. Android Studio automatically doesn't add it to the default drawable folder.
It usually happen because of the name assigned to image file. try to put the name of file in snake_case.[error][solution]
solutionC.pngerror
I'm trying to add an image in Android studio by right clicking on the drawable folder->new->Image Asset, I add an Action Bar and Tab Bar icon with a custom image and I click finish and it looks like its doing something but nothing appears in the drawable folder. I'm also unable to reference the new image name in any xml. What's funny is if I go to re-add this image, it says the image already exists and it will be overwritten. Am I doing something wrong?
I create a new project with Android Studio and generate image asset in the new project. It begins to work. I don't know what's wrong with the previous project. Hope it also helps for you.
As #Varun said, Before click on Finish, check save path by click on "Next" button.
TLTR: fix any other icon type you touched before.
In my case it was because of wrong path to foreground image path (the source image was deleted):
So even after changing the icon type the error does not disappear (buttons are disabled):
So fix other icon types.
In Background Layer set Asset Type to "Color"
my problem is that in version 4.2 the background in LinearLayout not showing, but in previous version it showing. I put the background like this:
android:background="#drawable/image"
I don't understand why.
I was just having the exact same problem. What fixed it for me was making sure I had the proper versions in the proper drawable-xxxx folder. For example...
If your image is in res/drawable but not in any other folder like res/drawable-hdpi, res/drawable-xhdpi, etc make sure you create a version appropriate for each of the screen sizes you are supporting and include that version in the corresponding drawable folder.
After I did that my bg drawable started showing up.
maybe it helps someone..I had a problem too with version 4.1.1 and everything I do was to set background programmatically
myLayout.setBackground(yourDrawable);
There isn't any problem with the syntax you are using. May be you are having some other problem. My advice would be to-
Try cleaning the project and run it again.
Check if you have the image named 'image.xxx' in your drawable folder.
Check if you are setting background of the correct layout.
or perhaps you can post some more code so that we can answer you more specifically.
Adding to the Above answer, check that the name of the image in drawable folder is in lower-case. All the drawables must have lower-case names.
I've downloaded the icons pack and the template pack from here: http://developer.android.com/guide/practices/ui_guidelines/icon_design.html#templatespack
and the icon pack and other stuff from here: http://developer.android.com/design/downloads/index.html.
I don't know how to put them in my app.
Is it in the code?
You can put them inside your res/drawable and use them in your app. You can either put them in your xml file or you can add them programatically.
Once inside the drawable, they can be accessed throug #drawable/resourcename in the xml file. eg,
android:background="#drawable/image1"
When doing it programatically, what we do is we set an imageview and load the drawable resource into the imageview.
ImageView iv = (ImageView)findViewById(R.id.imageView1);
iv.setImageDrawable(image);//where image is a drawable object
This would be a good read.
It must be in res/ folder of your project.
Put all of them in drawable folders of the project and then they can be accesses using R.drawable.file_name.
If you want to set the launch icon of your APP, you should put your icons into res/drawable-ldpi, -mdpi, -hdpi or -xhdpi.
Then create a folder, called drawable in res folder and add there images. then you may use them from XML by calling: android:src"#drawable/imagename.png" or programmatically getDrawable(drawable ID). You may also put your pictures into assets.
Right click the res/ folder and go to new->other.
Expand the Android folder and click android Icon set, then click next and follow the wizard all the way through.
Then you can do a clean and rebuild and they should be available!
I am completely new with Android/Eclipse. I can't figure out how to add an image in the /res/drawable folder of my Android Eclipse project.
Copy the image CTRL + C then in Eclipse select drawable folder, right click -> Paste
Drop in the image in /res/drawable folder. Then in Eclipse Menu, do ->Project -> Clean. This will do a clean build if set to build automatically.
Just copy the image and paste into Eclipse in the res/drawable directory. Note that the image name should be in lowercase, otherwise it will end up with an error.
Right click on drawable folder_new_file-
click on advanced button_
link to file in the file system_
then click on browse.
finish
You can just put it in on the file system. Eclipse will pick up the change on the next refresh. Click the folder and press F5 to refresh. BTW, make sure the file name does not have any capital letters... it will break android... and eclipse will let you know.
Thanks for the information .It helped me out as my project was somehow not visible in workspace therefore I had to insert the image from ECLIPSE IDE.
Also another way to do it is:
The image to be inserted should be copied ctrl+c and then right click on the drawable folder and PASTE it.
The image comes in drawable folder using ECLIPSE IDE.
You can use the image as an icon of the application using Manifest File-android:icon="#drawable/image_name"
Do you want to add an image from your computer? Just right click the folder in Eclipse and click Import
When inserting an image into the drawable folders, another import point in addition to the "no capital letters" rule is that the image name cannot contain dashes or other special characters.
Open folder path of Android application, open src folder then Add your image in /res/drawable folder
For Android Studio:
Right click on res, new Image Asset
On Asset type choose Action Bar and Tab Icons
Choose the image path
Give your image a name in Resource name
Next->Finish
The image will be saved in the /res/drawable folder!
Try to use jpg and png , also name your image in lowercase. Then drag and drop the image in res/drawable . then go to file and click save all . close eclipse then reopen it again . That is what worked for me .
You just need to copy/cut and paste the images into drawable folder using windows/mac file explorer
To refresh the workspace follow the steps mentioned in this question
Eclipse: How do i refresh an entire workspace? F5 doesn't do it
If that does not work you might wanna restart eclispe