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.

TOPICS

REFERENCE

2427 questions
1350
votes
28 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
  • 13,873
  • 6
  • 22
  • 29
1096
votes
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 android.app.Activity; import android.os.Bundle; public class ggps…
784
votes
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?
752
votes
13 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?
araks
  • 38,550
  • 8
  • 32
  • 39
552
votes
13 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
SoftReference
  • 6,039
  • 4
  • 16
  • 24
520
votes
21 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,500
  • 2
  • 17
  • 13
492
votes
5 answers

Defining custom attrs

I need to implement my own attributes like in com.android.R.attr 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
  • 17,956
  • 11
  • 34
  • 50
476
votes
12 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.
ataulm
  • 14,077
  • 7
  • 44
  • 90
465
votes
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?
David
  • 34,355
  • 30
  • 113
  • 139
423
votes
16 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
  • 21,393
  • 9
  • 50
  • 52
373
votes
9 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
  • 4,821
  • 3
  • 21
  • 30
322
votes
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…
zaid
  • 5,859
  • 7
  • 23
  • 20
288
votes
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…
Pentium10
  • 190,605
  • 114
  • 394
  • 474
286
votes
13 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…
SapphireSun
  • 8,236
  • 10
  • 44
  • 56
243
votes
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?
Roger
  • 6,177
  • 19
  • 55
  • 86
1
2 3
99 100