I have library project and main project. In library project, I have an icon with R.id.ic_generic_error and in main project, I have the alternative icon with the same id. In runtime, my app always display main project version of icon although I use package name like that com.libraryname.R.id.ic_generic_error.
Now I wanna use the icon of library. is it possible?
Give a different resource name to the library icon. Library resources are always overridden by project resources with the same name.
If you need the ic_generic_error icon to exist in the library project (because, for instance, it is referenced in a layout or in code), you can create an alias to the renamed library icon. See Creating alias resources for info on how to do this.
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.
How can I organize folders in Android Studio? Can I move all layout folders to one folder named "layout" for example?
No… but also yes.
You cannot change the organizational structure of the resource folders because that structure is how the Android framework determines which resources to load based on a given device configuration.
But you can change how the resources appear within Android Studio. Select the project view menu in the top-left corner of the Project Tool Window (shown below).
Then select Android. This will group all resources of the same type in a single resource folder, regardless of the resource qualifiers.
P.S. You will need to wait for any indexing to finish to see the resources grouped in this way; otherwise it will still show the resources in the default Project view style.
You can choose Android view in Project tab:
No, you cannot rearrange folders. But it seems you are using "Project Files" view type of that tree. Switch to "Android" to have some folders shown grouped.
I am using android studio 2.1.3,
i have import compile 'com.android.support:appcompat-v7:23+'. Now i want to use images from appcompat library in my application module. Please give reply as soon as possible.
I have attached screenshot. Please check image.
You cannot do that.Most of the resources in appcompat library is private.This library has public.xml in res/value of it and only the resources defined in this xml are accessible and the rest of the resources are implicitly private and android wouldn't give you suggestion to use them.Your best bet is to download a copy of it and put it in the drawable of your own application so you will be able to refer to them.
Resource: https://developer.android.com/studio/projects/android-library.html
For xml-
Make an imageview.
Write this inside the image view-
android:src="#drawable/name"
and it shall work
So now click on the clip art icon and there are hundreds of icons and pics. They are probably the same as of the external libraries. Click next for whichever image you want and that will be added to your drawable folder and then you can use it.
Add imageView in xml and add background.
android:background="#drawable/any_image_you_want"
I have several apps dependent on a library project. I wish them all to use the same launcher icons. Unfortunately this doesn't seem to be getting inherited?
I'm getting the generic icon for android...
I had the same problem: my App does not select the launcher icon on the library project but uses the default Android icon.
As suggested in comments, I inserted a line in the manifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mylib="schemas.android.com/apk/res/mylib.libpackage.libbase
package="myapp.apppackage.appbase"
android:versionCode="100"
android:versionName="2.1.0" >
The line is:
xmlns:base="schemas.android.com/apk/res/mylib.libpackage.libbase
the name space mylib.libpackage.libbase is the package name defined in the library manifes.xml.
to reference the launcher icon use
android:icon="#mylib:drawable/ic_launcher"
But.. this not works for me!
Simply I found I need to use the standard approach:
android:icon="#drawable/ic_launcher"
and deleted the ic_launcher resource form all libraries used in my project (except for the library used as icon resource).
Can you please tell me how can I use android's icon expander_ic_maximized?
I find that in frameworks/base/core/res/res/drawable-hdpi/expanderic_minimized.9.png
Here is my layout xml file:
<ImageView android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/expander_ic_minimized">
But I get this error:
res/layout/test.xml:70: error: Error: Resource is not public. (at 'src' with value '#android:drawable/expander_ic_maximized').
You can find all android icons in your android SDK installation directory. F.ex. /opt/android-sdk-linux/platforms/android-16/data/res/drawable-hdpi/ on my computer. There are different sets of icons for different android versions and for different screen resolutions. Copy expander_ic_minimized.png files to your project drawable folders and the icon will become available.
According to android developer guide:
Because these resources can change between platform versions, you
should not reference these icons using the Android platform resource
IDs (i.e. menu icons under android.R.drawable). If you want to use any
icons or other internal drawable resources, you should store a local
copy of those icons or drawables in your application resources, then
reference the local copy from your application code. In that way, you
can maintain control over the appearance of your icons, even if the
system's copy changes.
According to this thread, you will have to manually copy that icon into your project and use it from there.
Maybe just download and include it in your project
get it from expander_ic_maximized.9.png by clicking the View raw file link