I want to use Android OS drawables instead of providing my own.
How to access check mark icon?
I'm looking for check mark without rectagnle arround.
To access system provided resource, just access R.java file of Android.
for example:
android.R.drawable.checkbox_on_background // To access drawable resource
android.R.color.black // To access color resources
android.R.dimen.colorstrip_height; // To acess dimension resources
Update:
If you are using Android 2.3 Gingerbread then you can access below in-built drawables:
btn_check_buttonless_off.png
btn_check_buttonless_on.png
Related
I have some icons as drawable resources that I would like to put in specific locations in a MapBox map in android studio, but I don´t know how.
I have tried converting my resource files into bitmaps, and then convert those bitmaps into strings so as to fill the "withIconImage" method of SymbolOptions class.(I know it works with defined strings such as "airport", "fire-station").
Can someone help me?
Thank you!
This example from the Mapbox Android documentation shows how to add a local drawable resource from an Android application to your Mapbox map as a SymbolLayer. The initSpaceStationSymbolLayer helper method specifically takes care of this:
private void initSpaceStationSymbolLayer(#NonNull Style style) {
style.addImage(
"space-station-icon-id",
BitmapFactory.decodeResource(this.getResources(), R.drawable.iss)
);
style.addSource(new GeoJsonSource("source-id"));
style.addLayer(new SymbolLayer("layer-id", "source-id").withProperties(
iconImage("space-station-icon-id"),
iconIgnorePlacement(true),
iconAllowOverlap(true),
iconSize(.7f)
));
}
You mentioned SymbolOptions, however, so it is likely the case that you are using the Mapbox Annotation Plugin for Android rather than directly adding SymbolLayers. As indicated in the documentation for the SymbolOptions#withIconImage method, icon images are specified as Strings which reference the names of images in your style's sprite sheet. This example from the Mapbox Android Plugins demo app demonstrates how to add an image from the resources folder to your style, to then be used as the icon image in a SymbolManager. Namely, ID_ICON_AIRPORT is defined as "airport" here, then the helper method addAirplaneImageToStyle here adds the relevant image to the style, and finally a Symbol is created here using SymbolOptions#withIconImage and ID_ICON_AIRPORT passed as the argument. You use this same approach for adding your own drawable image.
I'm trying to write a tristate switch. But I'm failing to access the default com.android.internal.R.styleable.Switch_track drawable to use as background.
How to get that drawable?
Is there another approach for getting the default background?
You should not access private resources, you can't be sure that the resource will be available on all devices. And even if it is available, you can't be sure it will be the same.
If you want to use a private resource, you have to copy it into your project resources from SDK or Android sources.
Just for reference:
While it is not advised to access internal resources and you should be aware, that they can change or could be removed by a vendor or with an OS update, it is possible to access them at runtime:
int id = Resources.getSystem().getIdentifier("Switch_track", "styleable", "android");
Assume I've got 2 Application A and B.
I want to access resources (drawables, images, strings) of an B application from A application. How would I do that?
Edit:
You can also designate an Android project as a library project, which allows it to be shared with other projects that depend on it. Once an Android project is designated as a library project, it cannot be installed onto a device.
Does it mean That I can not use my library on android market?
My aim is to use default resources of Application A, but also if someone what he can download Application B and use it resources.
If you are the developer of both applications then the right approach would be, as othes noted, to create an Android library project and share it between apps.
Nevertheles, you can still access resources from another app, even if this is not your app:
Resources res = context.getPackageManager().getResourcesForApplication("com.example.foo")
If both apps are your own and you want to bundle these resources at build-time:
Create an Android Library Project, put all the needed resources into it and reference it from both your apps.
Edit to your edit:
You can use the library in the android market. You just can not use it alone (compile it). You have to build an app that uses the library. When you build that app, all the needed content gets basically grabbed from the library and copied to your apk. Which you can put on the market as usual.
This does not work when you want to access resources from an app that gets downloaded onto the device at runtime. A library project bundles all resources when you build the app that uses it. Peter Knego's response is the correct one when accessing at runtime.
It is possible if those both application are yours. Or you can used any Android Library for both these application. If you want you also create your own Android Library for this kind of work. Thnx.
Peter's answer above is great, but I'd like to elaborate a little more...
When you control appA and appB and want to get a drawable from appB, while in appA, then do the following:
Get the identifier of the drawable when in appB (for example, R.drawable.iconInAppB)
Then, in appA
Resources res = context.getPackageManager().getResourcesForApplication("com.example.appB");
Drawable d = res.getDrawable(integer);
//integer was what appB assigned to R.drawable.iconInAppB
*Note: The integer id assigned to R.drawable.iconInAppB will change over time so don't rely on hardcoding. I save the key-value pairs (String resourceName, int resourceId) in a database in appB and access them using a content provider.
For example, let's get the string-array with the ID of entryvalues_font_size from the package com.android.settings
String[] enries = null;
try {
// You can get PackageManager from the Context
Resources res = getPackageManager().getResourcesForApplication("com.android.settings");
int resId = res.getIdentifier("entryvalues_font_size", "array", "com.android.settings");
if (resId != 0) {
enries = res.getStringArray(resId);
}
}
catch (NameNotFoundException e) {
e.printStackTrace();
}
I am looking for the preset android files that come with the Android os. Can someone direct me to the source?
(Android install path)\android-sdk-windows\platforms\android-version\data\res
Hope this is what you mean.
Call the following as an example:
android.R.*
You can access built-in animations, layouts, text fields, whatever you need.
So if you wanted to find the default android black color, call the following:
View.setBackGroundColor(android.R.color.black);
This returns the INTEGER containing the pointer to the appropriate resource files.
All R files are generated as integer pointers, so this is the proper way to access these resources.
Hope this helped!
Try codesearch from google:
http://google.com/codesearch (choose android on the left side) or directly:
http://google.com/codesearch#cZwlSNS7aEw/frameworks/base/core/res/&exact_package=android
go to gen-> android.support.v7.appcompat ->R.java
Android generated a special called the
‘R’ file. This is a file of constants that allow you to
get Java references to the TextView you defined
in main.xml In fact, you can get references to all
kinds of in app resources you define! But remember
the String resources you defined in XML? You can
get references to those too.
You mean R.java? It will be in %project root%/res/android/%your project name%/
How can I add a Bitmap taken from the web (in the app i mean!) to the drawable resources? So i can access the Bitmap using R.drawable.bitmapName...
You can't modify that folder once your app is installed. In that case, you must copy the bitmap to a file and access it from there. Take a look at this other question:
Save bitmap to location
The resources are compiled at the apk building time, so you cannot change it in runtime. If you want to have some identifier you can consider creating a shared preference where you can put in relation the downloaded image file with some id. But it will take some effort from you to implement the functionality.