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
127
votes
11 answers

Avoid Android Lint complains about not-translated string

is it possible to specify that the strings in a file within the value-* directories are purposely not translated into other languages? I have a bunch of strings that are common for all the languages and need no translation, so I've created an…
Gianni Costanzi
  • 6,054
  • 11
  • 48
  • 74
109
votes
15 answers

Are there conventions on how to name resources?

Are there conventions how to name resources in Android? For example, buttons, textViews, menus, etc.
Eugene
  • 59,186
  • 91
  • 226
  • 333
103
votes
5 answers

Android: html in strings.xml

I would like display for example this html code:

Hello World

This is a test of the URL Example

This text is bold

This text is…

Alberto Alberto
  • 1,031
  • 2
  • 8
  • 6
100
votes
7 answers

how to get string from different locales in Android?

So I want to get the value of a String in several locales regardless of the current locale setting of the device/app. How should I do that? Basically what I need is a function getString(int id, String locale) rather than getString(int id) How could…
cheng yang
  • 1,692
  • 3
  • 12
  • 21
88
votes
4 answers

About Android image and asset sizes

I need to clarify some doubt about the image assets for my app, if I specify in an xml file that the height of something [image view] is 50 dip height which type of screen should i choose from the resources folder? drawable, hdpi, ldpi, mdpi,…
87
votes
5 answers

Programmatically change the value of a color resource obtained from API response

Let's say, on my API call I have a parameter that's called color. Is it possible to edit or modify an existent R.colors.color to assign the color from the API result? As an example: I make a call to my API and it returns green, now I want to load my…
Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148
85
votes
8 answers

Android XXHDPI resources

The Google Nexus 10 comes out shortly, and is the first device to use xxhdpi resources. It sports a display density of about 300 DPI (according to the Nexus 10 website and this calculator). However, when I go to the Android documentation, it…
Cat
  • 66,919
  • 24
  • 133
  • 141
81
votes
5 answers

How does the mapping between android resources and resources ID work?

It is magical for Android to locate the proper resource just through the R.id.XXX. AFAIK, the resources are compiled to binary format, so how does this mapping logic work under the hood? Maybe it works like this: For e.g., in the layout1.xml, we…
smwikipedia
  • 61,609
  • 92
  • 309
  • 482
78
votes
4 answers

Error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?

I have an Android app, which throws on BUILD process following error: /home/Ralf/Projekte/University/android-sampleapp/sampleapp/build/intermediates/bundles/debug/res/values-de/values-de.xml Error:(88, 5) Multiple substitutions specified in…
Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103
78
votes
26 answers

Android - How to regenerate R class?

Possible Duplicate: Developing for Android in Eclipse: R.java not generating I have imported a project into my Eclipse IDE, but it's giving me an error since R file is not generated automatically. How can I edit the R file so that it matches my…
zorglub76
  • 4,852
  • 7
  • 37
  • 46
75
votes
4 answers

ResourcesCompat.getDrawable() vs AppCompatResources.getDrawable()

I'm a bit confused with these two APIs. ResourcesCompat.getDrawable(Resources res, int id, Resources.Theme theme) Return a drawable object associated with a particular resource ID and styled for the specified theme. Various types of objects will be…
azizbekian
  • 60,783
  • 13
  • 169
  • 249
75
votes
1 answer

How to use Android quantity strings (plurals)

I am trying to use the getQuantityString method in Resources to retrieve quantity strings (plurals) based on Android Developer guidelines Quantity string (plurals) The error I am getting is Error:(604) Multiple substitutions specified in…
Andy
  • 1,023
  • 1
  • 9
  • 17
75
votes
13 answers

Gradle finished with non-zero exit value 1 (ic_launcher.png: error: Duplicate file)

I got this strange error with gradle, please help me! /.../app/build/intermediates/res/debug/drawable-xxhdpi-v4/ic_launcher.png: error: Duplicate file /.../app/build/intermediates/res/debug/drawable-xxhdpi/ic_launcher.png: Original is here.…
Fayçal
  • 1,150
  • 1
  • 12
  • 19
72
votes
26 answers

Failed linking file resources

This is the java file that is giving the error package com.example.daksh.timetable; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import…
Daksh Barad
  • 635
  • 1
  • 5
  • 10
72
votes
11 answers

How to access values from Android "strings.xml" in Kotlin

How can I access values from the Android strings.xml using Kotlin? class MainActivity : AppCompatActivity(), View.OnClickListener { override fun onClick(p0: View?) { getToastCalled("") TODO("not implemented") } private…
Dheeraj
  • 869
  • 1
  • 7
  • 13