Jake,
I haven't done a blog post about widget transparency, because my code
uses an internal API.
Nonetheless, my implementation is basically like this:
1 - I have a view group with a background image, which is the main
widget (sans the Launcher-style text label below).
2 - In widget code, I get a Method reference to
RemoteViews.setDrawableParameters using Java reflection.
3 - If there is an actual alpha value configured by the user, I use
reflection to call:
myRemoteViews.setDrawableParameters(<the view group id from above>,
true, alpha, -1, null, -1);
which adjust the alpha value for the "main" view group's background image.
Since this uses a method hidden from SDK applications, the usual
disclaimers apply: it may break on some versions of Android /
non-standard launchers, it may cause the launcher to run out of bitmap
memory (which may be why it's hidden).
As for using setAlpha(), available on 2.2 and above, that's an ImageView
method.
If you are going to use setAlpha (which is documented), you will need to
create the background with an ImageView, using its "source" image (as
opposed to the background drawable). The id in RemoteViews.setInt()
would then be the image view's id.
-- Kostya
28.04.2011 6:46, Jake Colman пишет:
KV> Calling "setInt" for "setAlpha" works starting with 2.2 - where
KV> ImageView.setAlpha is marked with @RemotableViewMethod.
>> I know this is doable because other application widgets have
>> sliders to set the transparency at runtime. But how?
Kostya,
Now I know for sure it's doable since you just released upgrades to your
widgets that do it!
Unfortunately, and I admit that I am being obtuse, I'm still not getting
it.
When I call RemoteViews.setInt(id,"setAlpha",value) what am I supposed
to be passing in for the id parameter? It's not the layout id since
that does not have a setAlpha method. I tried sending in the id of my
background drawable but that gave me an error that it could not find the
view.
What's the magic incantation? Have you done a blog posting on this?
-- Jake Colman -- Android Tinkerer
--
Kostya Vasilyev -- http://kmansoft.wordpress.com
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en