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
69
votes
4 answers

Creating integer array of resource IDs

I have some images in my res/drawable folder. Let's say img1.png, img2.png and img3.png. I am currently creating an integer array of these image IDs in Java like this int[] imgIds = {R.drawable.img1, R.drawable.img2, R.drawable.img3}; Instead, is…
android_stricken
  • 703
  • 1
  • 5
  • 5
67
votes
16 answers

Android Studio 3.1 Cannot Resolve Symbol (Themes, Widget, attr, etc.)

I upgraded Android Studio today to 3.1, and now Android Studio says it cannot resolve symbols for most of the resources (for example ThemeOverlay in styles.xml or ?attr/actionBarSize). This doesn't seem to prevent me from building or running in an…
65
votes
3 answers

How do I remove unused resources from third-party libraries I’ve included on Android?

The third-party libraries that I link into my app often include resource files that aren’t being used by my application, and as such, end up bloating my APK. For example, including the Google Play services library, but not using the login button…
Colt McAnlis
  • 3,846
  • 3
  • 18
  • 19
65
votes
14 answers

Fast ways to import drawables in Android Studio?

At some point in an Android project you will need to import some drawables - be it toolbar icons, images, UI features - in res/drawable directory. Most of the times you have images scaled for the most common qualifiers (drawable-hdpi, drawable-mdpi,…
natario
  • 24,954
  • 17
  • 88
  • 158
64
votes
7 answers

Double parameter with 2 digits after dot in strings.xml?

I want to have a parameter in one string in strings.xml and this parameter should be a double value. So I use %1$f. Here - http://developer.android.com/reference/java/util/Formatter.html there are many examples, but what if I want to have have a few…
lomza
  • 9,412
  • 15
  • 70
  • 85
64
votes
3 answers

What is the use of the res/values/public.xml file on Android?

I've searched on Google, but couldn't find any relevant results. I also checked the official Android docs and this page (for all the available resources) was all I could find. The relevant links (to the res/values/ directory) I found on this page…
Igor Popov
  • 9,795
  • 7
  • 55
  • 68
64
votes
5 answers

error: cannot find symbol variable abc_ic_ab_back_mtrl_am_alpha

I added a Fragment to my Android Studio project using New > Fragment > Fragment (Blank). As a result when I try to run, the project won't compile because it cannot resolve R.drawable.abc_ic_ab_back_mtrl_am_alpha in…
63
votes
8 answers

Android Raw folders - creation and reference

I'm trying to create a raw folder for my android app which will hold different media files for use later. But I can't seem to be able to reference the created raw folder in my .java classes. For example: R.? -> This returns a list of all possible…
Katana24
  • 8,706
  • 19
  • 76
  • 118
60
votes
8 answers

How to get access to raw resources that I put in res folder?

In J2ME, I've do this like that: getClass().getResourceAsStream("/raw_resources.dat"); But in android, I always get null on this, why?
Arkaha
  • 1,582
  • 3
  • 17
  • 19
56
votes
6 answers

Value equals to match_parent or fill_parent in dimens.xml?

Based on here on XML Attributes section I specify following in my dimens.xml: -1dp @dimen/match_parent
Rendy
  • 5,572
  • 15
  • 52
  • 95
54
votes
4 answers

How to use string resources in Android Jetpack Compose?

Let's I have the following strings.xml resource file: My Playground Hello %!