how to get images dynamically from drawable folder
You can use getIdentifier() for (int j = 1; j < 6; j++) { Drawable drawable = getResources().getDrawable(getResources() .getIdentifier(“d002_p00″+j, “drawable”, getPackageName())); }
You can use getIdentifier() for (int j = 1; j < 6; j++) { Drawable drawable = getResources().getDrawable(getResources() .getIdentifier(“d002_p00″+j, “drawable”, getPackageName())); }
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
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
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
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
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.
The raw folder must be inside the res folder, otherwise it won’t work.
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
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
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