Questions tagged [android-resources]

Android resources - framework for providing different layouts or strings for android projects.

You should always externalize resources such as images and strings from your application code, so that you can maintain them independently. Externalizing your resources also allows you to provide alternative resources that support specific device configurations such as different languages or screen sizes, which becomes increasingly important as more Android-powered devices become available with different configurations. In order to provide compatibility with different configurations, you must organize resources in your project's res/ directory, using various sub-directories that group resources by type and configuration.

Documentation about providing resources and working with them.



2524 questions
31 answers

Is there a way to get the source code from an APK file?

The hard drive on my laptop just crashed and I lost all the source code for an app that I have been working on for the past two months. All I have is the APK file that is stored in my email from when I sent it to a friend. Is there any way to…
Frank Bozzo
  • 15,033
  • 6
  • 25
  • 29
108 answers

R cannot be resolved - Android error

I just downloaded and installed the new Android SDK. I wanted to create a simple application to test drive it. The wizard created this code: package eu.mauriziopz.gps; import; import android.os.Bundle; public class ggps…
16 answers

Android getResources().getDrawable() deprecated API 22

With new android API 22 getResources().getDrawable() is now deprecated. Now the best approach is to use only getDrawable(). What changed?
14 answers

getColor(int id) deprecated on Android 6.0 Marshmallow (API 23)

The Resources.getColor(int id) method has been deprecated. @ColorInt @Deprecated public int getColor(@ColorRes int id) throws NotFoundException { return getColor(id, null); } What should I do?
  • 40,738
  • 8
  • 34
  • 39
14 answers

Is it possible to have placeholders in strings.xml for runtime values?

Is it possible to have placeholders in string values in string.xml that can be assigned values at run time? Example: some string PLACEHOLDER1 some more string
  • 6,969
  • 4
  • 19
  • 25
4 answers

getResources().getColor() is deprecated

Using: buildToolsVersion "22.0.1" , targetSdkVersion 22 in my gradle file. I found that the useful getResources().getColor(R.color.color_name) is deprecated. What should I use instead?
  • 37,109
  • 32
  • 120
  • 141
22 answers

Can the Android drawable directory contain subdirectories?

In the Android SDK documentation, all of the examples used with the @drawable/my_image xml syntax directly address images that are stored in the res/drawable directory in my project. I am wondering if it is explicitly not okay to create a sub…
Pepper Lebeck-Jobe
  • 5,870
  • 2
  • 19
  • 13
13 answers

How can I get color-int from color resource?

Is there any way to get a color-int from a color resource? I am trying to get the individual red, blue and green components of a color defined in the resource (R.color.myColor) so that I can set the values of three seekbars to a specific level.
  • 15,195
  • 7
  • 50
  • 92
6 answers

Defining custom attrs

I need to implement my own attributes like in Found nothing in official documentation so I need information about how to define these attrs and how to use them from my code.
Alexander Oleynikov
  • 19,190
  • 11
  • 37
  • 51
17 answers

Remove all unused resources from an android project

I want to remove all unused layouts, strings, drawables, colors, etc from my Android res directory. Are there any tools that will give me a list of files and I can remove from my repository and elements within specifics files (e.g. unused string…
Steve Prentice
  • 23,230
  • 11
  • 54
  • 55
10 answers

Load dimension value from res/values/dimension.xml from source code

I'd like to load the value as it is. I have two dimension.xml files, one in /res/values/dimension.xml and the other one in /res/values-sw360dp/dimension.xml. From source code I'd like to do something like…
Héctor Júdez Sapena
  • 5,329
  • 3
  • 23
  • 31
14 answers

Android XML Percent Symbol

I have an array of strings in which the % symbol is used. Proper format for using the % is %. When I have a string in that array with multiple % it gives me this error. Multiple annotations found at this line: - error: Multiple…
  • 6,259
  • 7
  • 26
  • 20
17 answers

getString Outside of a Context or Activity

I've found the R.string pretty awesome for keeping hardcoded strings out of my code, and I'd like to keep using it in a utility class that works with models in my application to generate output. For instance, in this case I am generating an email…
  • 9,170
  • 11
  • 46
  • 59
18 answers

How to clear an ImageView in Android?

I am reusing ImageViews for my displays, but at some point I don't have values to put it. So how to clear an ImageView in Android? I've tried: mPhotoView.invalidate(); mPhotoView.setImageBitmap(null); None of them have cleared the view, it still…
  • 204,586
  • 122
  • 423
  • 502
30 answers

"R cannot be resolved to a variable"?

In Eclipse, I've created a project from a source and now it shows errors - "R cannot be resolved to a variable". From what I found here, I had cleared and rebuilt the project, but still the R file doesn't appear in the /gen folder. Any ideas?
  • 6,443
  • 20
  • 61
  • 88
2 3
99 100