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

2524 questions
215
votes
21 answers

String Resource new line /n not possible?

It doesn't seem like it's possible to add a new line /n to an XML resource string. Is there another way of doing this?
Andi Jay
  • 5,882
  • 13
  • 51
  • 61
212
votes
3 answers

How can I assign an ID to a view programmatically?

In an XML file, we can assign an ID to a view like android:id="@+id/something" and then call findViewById(), but when creating a view programmatically, how do I assign an ID? I think setId() is not the same as default assignment. setId() is…
210
votes
10 answers

How to get a resource id with a known resource name?

I want to access a resource like a String or a Drawable by its name and not its int id. Which method would I use for this?
Aswan
  • 5,085
  • 10
  • 46
  • 70
195
votes
11 answers

Get color value programmatically when it's a reference (theme)

Consider this: styles.xml attrs.xml color.xml
Seraphim's
  • 12,559
  • 20
  • 88
  • 129
189
votes
13 answers

Lint: How to ignore " is not translated in " errors?

I can't compile/debug our Android app, because the localization files are not perfect yet. My IDE's validation tool Lint create errors saying: newCardsOrderVals is not translated in ar, bg, ca, cs Compiling/installing/running with Ant works fine,…
184
votes
17 answers

How can I get a resource content from a static context?

I want to read strings from an xml file before I do much of anything else like setText on widgets, so how can I do that without an activity object to call getResources() on?
lost baby
  • 3,178
  • 4
  • 32
  • 53
182
votes
14 answers

Android, getting resource ID from string?

I need to pass a resource ID to a method in one of my classes. It needs to use both the id that the reference points to and also it needs the string. How should I best achieve this? For example: R.drawable.icon I need to get the integer ID of this,…
Hamid
  • 4,410
  • 10
  • 43
  • 72
180
votes
5 answers

format statement in a string resource file

I have strings defined in the usual strings.xml Resource file like this: HELLO Is it possible to define format strings such as the one below result_str = String.format("Amount: %.2f for %d days ", var1,…
CocoNess
  • 4,213
  • 4
  • 26
  • 43
168
votes
5 answers

Android: What is android.R.id.content used for?

Anybody could explain the meaning of "android.R.id.content" ? How is it being used ? http://developer.android.com does not have any explanation. public static final int content Since: API Level 1 Constant Value: 16908290 (0x01020002)
koayst
  • 2,095
  • 3
  • 17
  • 16
166
votes
4 answers

When should I use the assets as opposed to raw resources in Android?

I'm in the mid of my Android studies, and I just covered the Assets and Raw resources. I'm trying to understand the reason for using Raw resources vs. Assets. They both provide with an uncompiled resource input stream. It seems that Assets provide…
Mortalus
  • 10,574
  • 11
  • 67
  • 117
158
votes
5 answers

Storing R.drawable IDs in XML array

I would like to store drawable resources' ID in the form of R.drawable.* inside an array using an XML values file, and then retrieve the array in my activity. Any ideas of how to achieve this?
gammaraptor
  • 1,886
  • 3
  • 14
  • 16
152
votes
26 answers

How to fix: android.app.RemoteServiceException: Bad notification posted from package *: Couldn't create icon: StatusBarIcon

I'm seeing the following exception in crash logs: android.app.RemoteServiceException: Bad notification posted from package com.my.package: Couldn't create icon: StatusBarIcon(pkg=com.my.package user=0 id=0x7f02015d level=0 visible=true num=0 ) …
135
votes
5 answers

How do I get the resource id of an image if I know its name?

How do I get the resource id of an image if I know its name (in Android)?
manu
  • 1,476
  • 2
  • 10
  • 6
133
votes
2 answers

Android: integer from xml resource

How do I have to modify my XML resources, or what XML file do I have to create, to access integer values in the same way you access string values with R.string.some_string_resource ? For example, in the code I want to say: ProgressDialog progressBar…
Terry
  • 14,529
  • 13
  • 63
  • 88
128
votes
4 answers

What Is The Difference Between -anydpi And -nodpi?

If you use the Vector Asset wizard in Android Studio 1.5.0, any vector drawable XML you import using that wizard goes into res/drawable/. However, the build/ directory, and the resulting APK show that those XML files get moved into a…
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491