setAlpha for RemoteViews problem

2019-06-21 08:44发布

I'm making an appwidget, and there's a bitmap on the widget of which I want to change it's transparency.

In the service I have:

RemoteViews remoteView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.myWidget);

remoteView.setInt(R.id.widgetPNG, "setAlpha", 50);

But it doesn't work. The emulator shows "Problem loading widget" on the home screen. I'm pretty sure everything else is fine cos when i changed the line to change it's imageResource it runs perfectly: remoteView.setInt(R.id.widgetPNG, "setImageResource", R.drawable.anotherPNG).

Can anyone help me? I've been stuck with this for a week...

2条回答
够拽才男人
2楼-- · 2019-06-21 09:08

Am fraid you can only call setInt() and friends on APIs which are marked with the @RemotableViewMethod annotation in the Android source code (example). Afraid setAlpha() is not one of them.

Maybe you could have two background images, a transparent one and a non-transparent one...

查看更多
祖国的老花朵
3楼-- · 2019-06-21 09:13

Set image in a src of imageview in XML. In java:

 if (Integer.parseInt(Build.VERSION.SDK) > Build.VERSION_CODES.ECLAIR_MR1) {
     rViews.setInt(R.id.imageview, "setAlpha", 30);
 }

try this one this support only available above 2.1

查看更多
登录 后发表回答