android-resources

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

自古美人都是妖i 提交于 2019-11-26 18:48:42
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 I thought it could be possible to change this value programmatically with the result from the API so I

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

北慕城南 提交于 2019-11-26 18:27:09
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 were: string resources style resources more resources These pages don't tell anything about the res/values/public.xml file. Here is an example I found for this type of file . Small snippet <?xml version="1.0" encoding="utf-8"?> <resources> <public type="attr" name="commentTextColor" id="0xAA010007" /> <public type="drawable" name="add_icon_bl" id=

Android: integer from xml resource

≯℡__Kan透↙ 提交于 2019-11-26 18:03:07
问题 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 = new ProgressDialog(getContext()); progressBar.setMax(getInteger(R.integer.maximum)); Is it possible? 回答1: Yes it is possible, it would look like this: Create an xml resources file in the folder /res/values/ called integers.xml. You are free to

What is the concept behind R.java?

倖福魔咒の 提交于 2019-11-26 17:45:59
问题 In android R.java is used to provide access to resources defined in XML files. To access the resource we need to invoke findViewById() method passing in the id of the resource to be fetched. This is similar to Spring where beans are defined in a XML context and are fetched by using application context. context.getBean("beanId") This provides loose coupling since the beans are defined externally and could be changed without making modifications to the code. This has me confused. Though what

Why does BitmapFactory.decodeResource scale my image?

限于喜欢 提交于 2019-11-26 17:21:14
问题 I have an image that is 120x120px located in my /res/drawable/ directory. This is the size required for all devices. To load this Bitmap, I am using the following: Bitmap tmpBmp = BitmapFactory.decodeResource(getResources(), R.drawable.myimage); The issue is that when I measure tmpBmp , the size is 360x360px. I know how to scale this back down to the 120x120 that I need, but it is a waste of processing time, although minimal. I am assuming that this has something to do with screen densities,

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

我们两清 提交于 2019-11-26 17:04:00
I'm in the mid of my studies in the Android world, 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 much more flexibility and functionality then Raw resources. a. You can create folder structure under Assets and not under Raw b. You can list all resources dynamically in the assets folder and not in the Raw folder. So, why would I use Raw resources in Android? The main differences between the raw folder and the Assets folder. Since raw

Accessing Resources without a Context

我的未来我决定 提交于 2019-11-26 16:39:57
问题 I'm trying to put configuration, such as URLs/etc, into a resource folder for a utility class to use. However, I don't want to pass the Context from the activities everywhere. I would like to be able to access a resource via a path name (seems like assets/ was designed for this use), without using a context to access the resource. In this particular case, I want a singleton to use something in configuration when it's instantiated. It has no need for anything from resources besides that one

Remove all unused resources from an android project

做~自己de王妃 提交于 2019-11-26 15:36:10
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 entries) that are no longer used? bakua You can easily search for unused resources from Android Studio. Just press Ctrl Alt Shift i and type " unused resources " (without quotes). That will execute lint. Super easy way to run lint commands (and other stuff from IDE). OR In Android Studio Menu > Refactor > Remove Unused Resources... Select the resources

getString Outside of a Context or Activity

牧云@^-^@ 提交于 2019-11-26 15:01:09
问题 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 from a model outside of the activity. Is it possible to use getString outside a Context or Activity ? I suppose I could pass in the current activity, but it seems unnecessary. Please correct me if I'm wrong! Edit: Can we access the resources without

setText fails to show a number as text in a TextView

五迷三道 提交于 2019-11-26 13:53:36
I have 4 buttons and 1 TextView. I want each of the buttons to add or subtract a different amount from the value (parsed to int) in the TextView. When I click on one of the buttons it throws fatal errors (listed below). I've searched some other Stackoverflow discussions and nothing seems to be working. Here is my current activity: public class PaydownSnowball extends Activity { int aAmt; String debtExtraPayment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.snowball); final Button plusTen = (Button) findViewById(R.id