In my project I want to add a menu bar. I have downloaded a menu icon now I want to add it under .Android -> Resources. Unfortunately I can't add anything (a prohibition sign appears as a mouse icon). I also tried to add only a png or another file which also does not work.
My project
The downloaded icons:
Does anyone know how I can add the files in the appropriate place?
Don't know if this is the case, but some times the projects lacks the actual 'Drawable' folder. Create the folder yourself from fileexlorer
Related
I'm brand new both to Xamarin and the Rider IDE, but not to Android. I'm going through some test projects, but when I make a new project, the ProjectName/Resources folder is missing things that I would expect to be there, most notably drawable. How can I create or get access to those directories so that I can do something like set the app icon?
I've tried creating a drawable directory, including it, and making sure that the build action is set to AndroidResource, but when I add Icon = #drawable/icon.png in the MainActivity, it doesn't recognize the drawable tag.
I found a solution for this. As I mentioned, I created the drawable folder manually, added the icon to it and made sure to right click and Include it. Then, in the manifest, I added android:icon="#drawable/icon and that got the icon to show up properly. So it didn't fix the issue of the folders not being generated, but at least for a simple task like updating the icon, it worked.
You can also declare in xaml.cs file, in your xaml form constructor the following:
x:Name_of_your_image/icon.ImageSource = (FileImageSource) ImageSource.FromFile("image/icon_name");
This way you won't need the drawable folders, as it will automatically provide the source of the image.
I made an Android layout file recently, and it worked like normal with being able to edit it via the text and design tabs.
Then, I don't know what I did, but the text in the file got grayed out, the android ui icon went away where the files are listed on the left hand side, and I can't call them from inside my Java code. What can I do to convert these files back to Android layout files? Cleaning and rebuilding doesn't work.
You can't put layout files into subfolders, that's why they're not working.
Move them out of the subfolder and into the main folder and they will work again.
In Android Studio, I want to create the folders values-v14 values-v21 inside the res folder.
But when I tried to make it like: right click on res folder select option New >Directory, then after creating the folder, it is not visible in Android Studio. But when I select the option Show in Explorer, then it is visible.
How do I create a folder in Android Studio, so that I can change files like styles.xml, etc?
Try to switch from Android to Project as shown below
Switching from the Android view to the Project view will allow you to see the directory structure, but it is less convenient for viewing and editing Android files.
There is a better way. Don't use New > Directory.
Right click values and choose New > Values resource file.
Select Version from the list and click the >> button. Write styles as the file name and 14 as the version number and click ok. (Repeat all this for version 21.)
Android Studio will automatically create values-v14 and values-v21 directories with the new styles.xml files in them. And in your Android project view you conveniently see all three styles.xml files together.
Other directories and resource files can be similarly added.
Layout files
Language translations
You can also manage language stuff with the editor, it´s a little faster.
Instead to looking for the file from ANDROID, go to PROJECT and then look for the folder, you will find it there...
I believe this is like version control, where the folder exists, but you need a file inside in order to view it. I just ran into this, and the folders existed but didn't show up until I had a file inside of them.
I hate to think this is by design. The use-case of a developer hiding their own work-space? Collapsing makes more sense
it's so simple to find your new values-v21 or recently created..
(1) - Go to project files
(2) - app > src > main > res
(3) - if here is not visible your directory then
(4) - right click on res and select show in explorer
(5) - Go inside res here all your files are shows
(6) - Then Go inside values > copy style file from there and come back to paste inside your values-v21 folder
(7) - you are done .. go to your android studio and see your folder values-v21 is appearing.
Note :- Your folder was empty so you folder was not appear in android studio.
I am trying to create a new folder inside the /res directory
I added a new directory
The folder does not appear in the /res folder even though it exists in the finder
Case and point I tried adding the folder again and I got a message telling me it exists.
If you can suggest what I can do to fix this I'd love it!
(And yes I have restarted the program as well as my computer)
Turns out there is a selector at the top which, by default, is set to show Android. If you flick the toggle down to 'Packages' you can see your own packages.
In Android Studio you can add new directories by right clicking the resource folder in the Android view. (Don't get confused by the New Directory option.)
For example, if you want a new layout resource file and folder then right click layout and choose New > Layout resource file.
If you want a new layout-sw600dp for the activity_main.xml file then choose Smallest Screen Width from the list and click the >> button. Fill in the file name and width and click ok.
Android Studio will automatically create the layout-sw600dp directory and in the Android view you will have both layout files conveniently displayed next to each other.
It is a similar process for adding other resource directories and files (see my other example).
Clicking at TAB Android in top, select the perspective Project Files. Then u can see all folders of project.
Android 4.0
The Android view by default seems to conceal the duplicated resource type directories in the side panel.
If you want to view the duplicate resource type directories i.e. drawable for two different languages,
switch the view from "Android" to "Packages" or "Project" or "Project Files"
Browse the actual folder structure in windows and you'll see the folder. Put the same resource file found in the normal drawable folder into this new directory. Then when you go back into Android Studio you'll now see 2 files under the NORMAL \res\drawable structure. Make sure you don't look for a subfolder in Android Studio called "drawable-sw600dp" because you won't find it other than in windows explorer. What you will find in Android Studio (after you copy the resource file) is a new resource file along with your original called "jenny-web.png (sw600dp)" or something similar. This same principle resolves the same error when working with other resources like layouts.
For Android Studio 3.0, those who are following https://developer.android.com/training/basics/supporting-devices/languages.html and have encountered the same issue as the one stated in this question, you can also do the following aside from the above answers which are helpful.
Right click to the target folder (i.e. res folder) > New
Choose Android Resource File
Specify the file name, and in the Directory name field put the folder name you want to create or the existing folder you want to put the resource file.
After hitting OK, in the Project files dropdown, you will see the correct strucutre.
And in the Android dropdown, you will see it as part of the strings.xml under values folder.
This worked best for me. What I did was I right-clicked the 'app' directory and chose 'New' >> 'Android Resource File'. After that I filled in the File Name with 'strings'. Chose 'XML' as my resource type and my Directory Name was 'values-b+za+ZA'.
This created everything as I wanted it to, however, values-b+za+ZA, still didn't show in the Android view but it shows in the Package view. (The views you choose from the top dropdown.)
The difference this time is that in the Package view I can still see my new 'strings.xml' file and in the Android view I van also see the new 'strings.xml' file.
I guess android studio doesn't show custom directories in the Android view but creates like some kind of link to the true directory when working with it. I am not familiar with Android Studio at all but this did work for me. If there are more professional answers please feel free to correct me.
You most probably have the file named in Uppercase, Android Studio does not recognize file names in Uppercase, I had made this mistake a while back.
As the developer doc states:
be sure the Project window is open (select View > Tool Windows > Project)
and the Android view is selected from the drop-down list at the top of that window.
You will then be able to see all relevant project files (including new ones) in a more efficient way.
Hope it helps someone.
This is odd but in my case i had to many underscores delimiters.
When i renamed yt_search_view (2 delimiters) to yt_searchview (1 delimiter), it appear in project view where it should be. It is probably a bug. My version is Android Studio 3.2.
Also, i notice that if i add a value folder to the layout folder, it also fix the issue.
Example:
layout_control_x
--layout
----top_panel.xml
--values <--adding this empty folder fixed the problem
For complete information on how to add sub folder layouts check this.
I put an image in my res/drawable folder, but when I clean and build my project, I receive the error message R cannot be resolved. I don't understand why this happens, what should I do?
Check out the following link:
http://source.android.com/source/using-eclipse.html
Note: Eclipse sometimes likes to add an "import android.R" statement at the top of your files that use resources, especially when you ask eclipse to sort or otherwise manage imports. This will cause your make to break. Look out for these erroneous import statements and delete them.
After removing the erroneous imports, delete your R.java file and try to clean and build the project again. If the problem still persists, post here.
possible causes:
duplicate file names (across all drawables folders) . for example , is there a file named "h1.png" and also "h1.jpg" ?
bad files names . only letters allowed are lowercase english ones , and digits.
hidden files , like those of the OS . on windows , it's probably "Thumb.db" . either delete them , or delete & disable them. linux and mac also have such files , but with different names and usually start with "." .
Make sure your image name is in small latters and in res/drawable folder.for how we add drawables in our project and supported images formats see docs Drawable Resources
Might be you are using android.R.drawable.your_image
Remove android.R from imports. use R.drawable.your_image
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!