Is there an Enum string resource lookup pattern for Android?

You can certainly look up a resource by its name using Resources.getIdentifier(). For instance, with the string resources you posted as an example, you can do this from an activity: Resources res = getResources(); MyEnum e = MyEnum.VALUE1; String localized = res.getString(res.getIdentifier(e.name(), “string”, getPackageName())); From a View, you’d have to change the last argument to … Read more

Android: How to get string in specific locale WITHOUT changing the current locale

You can use this for API +17 @NonNull @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static String getStringByLocal(Activity context, int id, String locale) { Configuration configuration = new Configuration(context.getResources().getConfiguration()); configuration.setLocale(new Locale(locale)); return context.createConfigurationContext(configuration).getResources().getString(id); } Update (1) : How to support old versions. @NonNull public static String getStringByLocal(Activity context, int resId, String locale) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) return getStringByLocalPlus17(context, resId, … Read more

Duplicate value for resource ‘attr/font’ with config “

It may the concept that makes conflicts with the logic that we have previously used for apply Custom fonts. Previously We have used below code for creating the custom attribute for the font. <declare-styleable name=”CustomFont”> <attr name=”font” format=”string” /> </declare-styleable> What I change In my case, this was the issue and I have resolved it … Read more

Android Resources$NotFoundException: Resource ID #0x7f030027

You can check your R file for Resources$NotFoundException: Resource ID #0x7f030027. It’ll tell you which resource was creating the problem. As an alternative solution I think you might have setText or any content just an int.And as you know here compiler will look for corresponding resource value. So, just concat an empty string there as … Read more

Value equals to match_parent or fill_parent in dimens.xml?

Use this, it works for me <dimen name=”custom_wrap_content”>-2px</dimen> <dimen name=”horizontal_border_height”>@dimen /custom_wrap_content</dimen> <dimen name=”custom_match_parent”>-1px</dimen> <dimen name=”vertical_border_height”>@dimen /custom_match_parent</dimen> And the Reason why match_parent doesn’t run. You cannot supply a build in keyword like match_parent Edit: Use px instead of dp as suggested by Jarett Millard in the comments.

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

The file res/values/public.xml is used to assign fixed resource IDs to Android resources. Consider these set of string resources in res/values/strings.xml: <?xml version=”1.0″ encoding=”utf-8″?> <resources> <string name=”string1″>String 1</string> <string name=”string3″>String 3</string> </resources> The Android Asset Packaging Tool (aapt) might assign the following resource IDs for these resources when the app is compiled: public final class … Read more

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

Just adding to @David Airam’s answer here; the “incorrect” solution he gives is actually correct, but with a bit of tweaking. The XML file should contain: <string name=”resource1″>Hello string: %1$s, and hello float: %2$.2f.</string> Now in the Java code: String svalue = “test”; float sfloat= 3.1415926; String sresult = getString(R.string.resource1, svalue, sfloat); The exception that … Read more

error: cannot find symbol variable abc_ic_ab_back_mtrl_am_alpha

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_material Edit: In 23.2.1 the name of the component was changed back to abc_ic_ab_back_mtrl_am_alpha Edit: In 24.0.0 the name of the component was changed to: abc_ic_ab_back_material

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)