android-resources

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

a 夏天 提交于 2019-12-17 04:27:48
问题 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 app with i.e (green Toolbar , green TextView color, etc.), is that possible? My first thought was: Create a item on colors.xml called demo then assign it a default color, then use this demo color wherever I want ( Button , TextView , etc.) Then

findViewById() returns null for Views in a Dialog

廉价感情. 提交于 2019-12-17 04:08:27
问题 The problem is, no matter where or how I call for this layout's components, they always return null. setView(inflater.inflate(R.layout.search_layout, null)) This works fine. It displays the layout inside the Dialog , yet, the children are always returned as null by findViewById(R.id.some_search_layout_children) . I've tried cleaning my project multiple times, tried to implement another class for my Dialog , called findViewById() as a member of my main Activity , inside the initSearch() method

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

╄→尐↘猪︶ㄣ 提交于 2019-12-17 03:50:36
问题 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) 回答1: As Philipp Reichart commented: android.R.id.content gives you the root element of a view, without having to know its actual name/type/ID. Check out http://stackoverflow.com/questions/4486034/android-how-to-get-root-view-from-current-activity 回答2: The android

How to easily iterate over all strings within the “strings.xml” resource file?

眉间皱痕 提交于 2019-12-14 02:18:17
问题 I created an application that uses the TTS engine to send feedback to the user. With the aim to improve the performance, I used the synthesizeToFile and addSpeech methods, but strings of text to be synthesized are inside the strings.xml file, so I have to invoke these methods for each string that is spoken by the TTS engine. Since the TTS engine uses only strings whose name begins with tts_ , is it possible to easily iterate over all strings that begin with tts_ within the strings.xml file?

Localization of android application. One string resources for several countries

本小妞迷上赌 提交于 2019-12-13 20:18:38
问题 I have such a question: I have an Login/Registration Activity which is by default is using Russian version of strings.xml. So when user is entering application - he sees text in Russian language. But on that activity there is a button to choose another language. When he clicks that button - I open another activity in which he can choose which language to use (English/Spanish/German/etc). When he chooses a language (let's say German). How can I from this point in time, show to the user text

The sense of providing MDPI and HDPI resources

五迷三道 提交于 2019-12-13 15:19:24
问题 For every app I'm developing I provide mdpi, hdpi, xhdpi, xxhpi resources (also launcher icon for xxxhdpi). Less and less devices are mdpi/hdpi that's why I'm wondering if is there any sense to provide these resources? Both xhdpi and xxhdpi resources can be easily scaled down to mdpi and hdpi accordingly (ratio 0.5). The documentation states: For example, when looking for a low-density resource and it is not available, the system prefers to scale-down the high-density version of the resource,

Splash Screen triggers Resources$NotFoundException only on Android 8.1

馋奶兔 提交于 2019-12-13 13:39:59
问题 I followed this tutorial here step by step, it works fine on my API 21 emulator, but on my 27 it crashes as soon as the app loads with: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.myapp/com.myapp.myapp.ui.SplashScreenActivity}: android.content.res.Resources$NotFoundException: Drawable com.myapp.myapp:drawable/splash_screen_background with resource ID #0x7f0700a9 My file drawable/splash_screen_background is this one: <?xml version="1.0" encoding="utf-8"?>

In Android, is there a reason to use string resources for strings that are not going to be translated?

风格不统一 提交于 2019-12-13 13:06:26
问题 I'm wondering what the drawbacks are for using strings that are defined in the java files in Android code. I like to use plain old Java strings for things that are not visible strings like e.g. names in XML documents that I'm parsing, or keys for bundles. Seems to be a good idea to just keep all those things in the java file where they are used instead of moving them out into an XML file and making the code more complicated. Yet, I see many examples of Android code that seem to put every

How can resolve R in Android?

孤街浪徒 提交于 2019-12-13 10:11:38
问题 I was run the program to guess random number but in case R, their should be "R cannot be resolved to a variable" error comes many time . And i am also try to import android.R; but could not work without errorless. error comes in to "main" or "R.layout.main". so please fix the problem. public class GuessGame extends Activity { Button btnGuess; private EditText enter; private GuessGame mcontext; private Double guess; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate

Using same drawable image in two different folder to support all tablets.(same image (no change)in two folders)

孤街浪徒 提交于 2019-12-13 08:59:45
问题 I want to keep same images in two folders drawable-large-xhdpi and drawable-xlarge-hdpi. avoiding duplication of images reduces memory How? I am having images of 1920x1080 resolution Any usefull answer i am very thankful to all. (example: if the image is half of screen width , it should be half of the screen in all tablets) 回答1: If you want to keep exactly the same image in drawable-large-xhdpi and drawable-xlarge-hdpi then you apparently do not really understand what these xhdpi and hdpi