android-color
How to darken a given color (int)
A more Android way of doing it: public static int manipulateColor(int color, float factor) { int a = Color.alpha(color); int r = Math.round(Color.red(color) * factor); int g = Math.round(Color.green(color) * factor); int b = Math.round(Color.blue(color) * factor); return Color.argb(a, Math.min(r,255), Math.min(g,255), Math.min(b,255)); } You will want to use a factor less than 1.0f to darken. … Read more
Change color of the drop down arrow of Spinner in XML
There are three ways to achieve that. 1. Through code: In your xml, make sure your spinner has an id. Let’s say we have a spinner with id “spinner”. In your code, add the following in your onCreate(): Spinner spinner = (Spinner) findViewById(R.id.spinner); spinner.getBackground().setColorFilter(getResources().getColor(R.color.red), PorterDuff.Mode.SRC_ATOP); where red is your defined color in colors.xml in the … Read more
How do I create ColorStateList programmatically?
See http://developer.android.com/reference/android/R.attr.html#state_above_anchor for a list of available states. If you want to set colors for disabled, unfocused, unchecked states etc. just negate the states: int[][] states = new int[][] { new int[] { android.R.attr.state_enabled}, // enabled new int[] {-android.R.attr.state_enabled}, // disabled new int[] {-android.R.attr.state_checked}, // unchecked new int[] { android.R.attr.state_pressed} // pressed }; int[] colors … Read more
getResources().getColor() is deprecated [duplicate]
It looks like the best approach is to use: ContextCompat.getColor(context, R.color.color_name) eg: yourView.setBackgroundColor(ContextCompat.getColor(applicationContext, R.color.colorAccent)) This will choose the Marshmallow two parameter method or the pre-Marshmallow method appropriately.