android-resources

Is there an Enum string resource lookup pattern for Android?

醉酒当歌 提交于 2019-11-27 14:21:31
问题 I have an enumeration where I need to display the values as localized strings. My current approach has been this: public enum MyEnum { VALUE1(R.string.VALUE1), VALUE2(R.string.VALUE2), . . VALUE10(R.string.VALUE10); private int mResId = -1; private MuEnum(int resId) { mResId = resId; } public String toLocalizedString(Resources r) { if (-1 != mResId) return (r.getString(mResId)); return (this.toString()); } } Is there any easier way to to do this? I'd love it if I could somehow lookup the

ERROR No package identifier when getting value for resource number

廉价感情. 提交于 2019-11-27 14:21:00
Both activities are in the same package Second activity uses second layout file setContentView(R.layout.main2); Errors on this line in the Second_Activity. EditText text1 = (EditText) findViewById(R.id.EditText03); Here is the layout file for the Second_Activity. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content"

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

前提是你 提交于 2019-11-27 14:20:02
问题 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 double/float parameters and I want only the second one to have 2 digits after . ? I tried to use combinations like %2$.2f or %2.2$f . Nor of them worked. %.1f does not work as well. So, does anybody know how can I "customize" a float/double value

Accessing Resources without a Context

别等时光非礼了梦想. 提交于 2019-11-27 14:18:39
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 time during instantiation. Therefore, having to pass in a Context every time getInstance() is called

Getting resources of another Application

妖精的绣舞 提交于 2019-11-27 13:45:47
Assume I've got 2 Application A and B. I want to access resources (drawables, images, strings) of an B application from A application. How would I do that? Edit: You can also designate an Android project as a library project, which allows it to be shared with other projects that depend on it. Once an Android project is designated as a library project, it cannot be installed onto a device. Does it mean That I can not use my library on android market? My aim is to use default resources of Application A, but also if someone what he can download Application B and use it resources. If you are the

Android: integer from xml resource

馋奶兔 提交于 2019-11-27 11:37:33
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? Terry 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 give it any name as you want, but choose one that is obvious. In that resources file, create your

Avoid Android Lint complains about not-translated string

坚强是说给别人听的谎言 提交于 2019-11-27 11:23:57
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 unlocalized-strings.xml file within values directory.. Running Android Lint to check for problems it keeps saying that some translations are missing.. I do not want to disable this check on the whole project, I'd like to disable it only in some XML files.. is it possible? "title_widget_updater_service" is not translated in de, en, en-rUS, it Issue: Checks

error: cannot find symbol variable abc_ic_ab_back_mtrl_am_alpha

谁说我不能喝 提交于 2019-11-27 11:02:53
问题 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 toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha); Any ideas how to solve this? It looks like I also lost access to android:buttonTint 回答1: The name of the resource was changed in the 23.2.0 support library. Modify abc_ic_ab_back_mtrl_am_alpha to abc_ic_ab_back

Are there conventions on how to name resources?

。_饼干妹妹 提交于 2019-11-27 10:38:23
Are there conventions how to name resources in Android? For example, buttons, textViews, menus, etc. Ian I don't know whether there are any official recommendations. For ids in my layouts with widgets and containers, I use the convention: <layout>_<widget/container>_<name> I do the same strategy for any dimens, strings, numbers, and colors I use in those layouts. However, I do try generalizing. e.g if all buttons have a common textColor, I won't prefix the name with the layout. The resource name would be 'button_textColor'. If all textColors are using the same the resource it will be named

getString Outside of a Context or Activity

此生再无相见时 提交于 2019-11-27 10:06:55
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 using Context ? Gangnus Yes, we can access resources without using `Context` You can use: Resources