problems when setting / removing color filter to image views

by Romain Guy » Thu, 29 Jan 2009 01:09:59 GMT

Sponsored Links

The problem comes from a rather unknown feature of resources and
drawables. The state of several drawables that come from the same
resource is shared across all the drawables. Take this example:

Drawable d1 = getResources().getDrawable(R.drawable.my_image);
Drawable d2 = getResources().getDrawable(R.drawable.my_image);

d2.setAlpha(0); // Sets the alpha value of d2 *and* d1 to 0

The two drawables are different objects but they both use the same
"constant state" (it's the actual name of the implementation) which
contains, among other things, the alpha value, the bitmap... and the
color filter.

This behavior comes from the necessity to optimize the memory usage
and the loading times of applications. By doing so we have only one
constant state used by all buttons across all applications.

Romain Guy
Android framework engineer

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them


Other Threads

1. How to resize the RelativeLayout or any other Layout in Android ?

yes..u can do it by giving the values to width and height of the
but this is always not advisable.


2. Android SQLite3 Sync With Desktop

I am starting a new application. One of the requirements for it is to
sync with a desktop SQL database. I am looking for some tips and
tutorials on doing that. I am new to Android, so please be gentle :-).
I have a ton of dev exerience in both app and database software, I am
just new to Android.

I have my application created and am already reading and writing
SQLite3 data. My next step is the sync with a desktop application.


3. Droid Video Recorder

4. Show one contact view

5. How to know whether Activity/service is running or stopped

6. Animation for Bitmap

7. QoS Control in Android