setAlpha for RemoteViews problem

妖精的绣舞 提交于 2019-12-12 10:48:36

问题


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...


回答1:


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...




回答2:


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



来源:https://stackoverflow.com/questions/4313274/setalpha-for-remoteviews-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!