android-resources

Using string from resource XML in Switch?

白昼怎懂夜的黑 提交于 2019-12-10 12:37:55
问题 New to Android here, so I apologize if this is a simplistic question. I am attempting to use a switch based on string resources in my XML. It would look something like this: switch (myStringVariable) { case getResources().getString(R.string.first_string): break; case getResources().getString(R.string.second_string): break; case getResources().getString(R.string.third_string): break; default: break; } Unfortunately, this won't work. The error that I get is "Constant expression required". Is

how to create new android xml file in drawable folder that does not have Drawable resource

℡╲_俬逩灬. 提交于 2019-12-10 12:04:38
问题 this might sound silly. i am trying to do tab layout for android. there is a part where i need to create a drawable folder and have android xml file in that particular folder. i have looked into all the tutorial and youtube for this. The tutorial shows create a new android xml file and choose Drawable for the type of the resources. in my case, i cannot create new android xml file with Drawable as the type of resources as Drawable does not exist. Below shows the interface. is there anyway can

How to add locale(with country) to font resources (Support Library v26)?

假如想象 提交于 2019-12-10 02:58:40
问题 Google published the official font resources handling since support library v26 released: https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html However, looks like I cannot add country qualifier for the font resources folder. I have an app which has 3 languages: English, Traditional Chinese and Simplified Chinese. And I tried to name my font folder under res this way: font font-zh font-zh_CN (I have also tried font-zh-CN ) (Note that zh is the language, while CN is the

Using a BindingAdapter with a string-array from the resources

≯℡__Kan透↙ 提交于 2019-12-10 02:09:56
问题 I have an almost simple idea: I want to generate an Adapter for a spinner with the data binding API and an BindingAdapter. Here is the XML I want to use: <Spinner android:id="@+id/country" android:layout_width="wrap_content" android:layout_height="wrap_content" app:value="@{address.country}" app:data="@{@array/countries}" app:keys="@{@array/iso_3166_2}"/> Address here is a simple class which has a field called country which is a String and will contain a ISO-3166-2 String. To keep it simple

Is it possible to set xml layout as a view not from resources dynamically?

前提是你 提交于 2019-12-09 13:53:03
问题 I want to set dynamic layout which is not present in resource like res or values.If it is present in my file-manager and i want to set that layout as a view layout.Is it possible to set dynamic layout to the views, without building app.I want to send the layout from the server and download the layout and set for the view without building and not from the resources.Is Butter knife used for this process or it's just for binding views to the variables. 回答1: Try Proteus Proteus is meant to be a

Android: Standards for prefixing files in the RES directory apart from ic_?

耗尽温柔 提交于 2019-12-09 08:49:08
问题 anyone know if there a list of standard prefixes that we need to use (or advisable to use) in the RES directory. i.e. Android recommends ic_ for icons, which is great and i am following that. But what about Logos, button images, navigation images etc? I would really be interested to find out if other exist and what everyone else is using Thanks in advance 回答1: Use common naming conventions for icon assets Try to name files so that related assets will group together inside a directory when

Android Studio can't find color reference within the same resource file

北城以北 提交于 2019-12-08 18:52:30
Here's the content of my resource file \res\values\colors.xml : <?xml version="1.0" encoding="utf-8"?> <resources> <color name="themeGray">#ff8A9199</color> <color name="themeLightGray">#ffeaeaea</color> <color name="themeDarkGray">#ff3f434b</color> <color name="themeRed">#ffCC292B</color> <color name="themeBlue">#ff002E63</color> <color name="themeWhite">#ffffffff</color> <color name="buttonNormal">@color/themeGray</color> <color name="buttonPressed">@color/themeBlue</color> </resources> The two values @color/themeGray @color/themeBlue are red colored Cannot resolve symbol '@color/themeGray'

How to reference a string in strings.xml of an Android library in code?

隐身守侯 提交于 2019-12-08 17:07:26
问题 To reference string foo in strings.xml (in res\values) of an app project, one can simply use getString(R.string.foo) getString is a method of Context. Suppose an Android library has a string foo in its strings.xml. How can it be used in a method of the library? Edited: It has been suggested to pass a reference of Context to the library method so getString() can be used. Since it is a context of an app's project, there is potential conflict that can be illustrated as following: Suppose: The

Switch between reference and value preview of string resources in the xml editor

左心房为你撑大大i 提交于 2019-12-08 16:27:39
问题 when working in Android Studio in xml values and referencing to @Strings/xy for instance, I have seen in a video, that it is actually possible to display the actual values directly in the same editor window. It was basically a switch to between @String/xy and "XYContent", but with the reference still existing. I am not referencing to "ctrl+click" which opens (in my case) the strings.xml in a new tab. Any idea? Couldn't find any reference to this in the help file. 回答1: Click and bring the

Robolectric throws Resources$NotFoundException when trying to access resource in raw folder

[亡魂溺海] 提交于 2019-12-08 16:05:15
问题 When I try to access a raw resource I receive an android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f060000 error. The resource is a .bks certificate, used for server validation. It is stored on the res/raw folder. The most awkward thing is that when I copied the certificate (and the validation architecture) to a fresh project (that I built just to test this), it worked! I'm using nenick's custom runner, so Robolectric can correctly find the folders for manifest,