getResources().getColor() is deprecated [duplicate]

This question already has answers here: getColor(int id) deprecated on Android 6.0 Marshmallow (API 23) (13 answers) Closed 6 years ago. Using: buildToolsVersion “22.0.1” , targetSdkVersion 22 in my gradle file. I found that the useful getResources().getColor(R.color.color_name) is deprecated. What should I use instead? 4 s 4

Can the Android drawable directory contain subdirectories?

In the Android SDK documentation, all of the examples used with the @drawable/my_image xml syntax directly address images that are stored in the res/drawable directory in my project. I am wondering if it is explicitly not okay to create a sub directory within the drawable directory. For example, if I had the following directory layout: … Read more

Is it possible to have placeholders in strings.xml for runtime values?

Is it possible to have placeholders in string values in string.xml that can be assigned values at run time? Example: some string PLACEHOLDER1 some more string 14 s 14 Formatting and Styling Yes, see the following from String Resources: Formatting and Styling If you need to format your strings using String.format(String, Object…), then you can … Read more

getColor(int id) deprecated on Android 6.0 Marshmallow (API 23)

The Resources.getColor(int id) method has been deprecated. @ColorInt @Deprecated public int getColor(@ColorRes int id) throws NotFoundException { return getColor(id, null); } What should I do? 13 s 13 Starting from Android Support Library 23, a new getColor() method has been added to ContextCompat. Its description from the official JavaDoc: Returns a color associated with a … Read more

Android getResources().getDrawable() deprecated API 22

With new android API 22 getResources().getDrawable() is now deprecated. Now the best approach is to use only getDrawable(). What changed? 16 s 16 You have some options to handle this deprecation the right (and future proof) way, depending on which kind of drawable you are loading: A) drawables with theme attributes ContextCompat.getDrawable(getActivity(), R.drawable.name); You’ll obtain … Read more

R cannot be resolved – Android error

I just downloaded and installed the new Android SDK. I wanted to create a simple application to test drive it. The wizard created this code: package eu.mauriziopz.gps; import android.app.Activity; import android.os.Bundle; public class ggps extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } … Read more