Search code examples
androidbackgroundimageviewremoteview

How to set background of ImageView in a Notification's RemoteView in Android?


I've transplant Android's Notification, How to set background of ImageView in a RemoteView of Notification, and set it to transparent?

I tried

remoteViews.setInt(R.id.icon, "setBackgroundResource", 0x00000000);

but it not worked.

I think the problem is I can't get R.id.yourFrame from Android framework in another app process. So the code above is just apply for the current widget process.

So how can I get the compiled R.id.icon as a int? I want to try in this way.


Solution

  • Try this

    remoteView.setBackgroundColor(0x0000FF00);

    or

    remoteView.setInt(R.id.yourFrame, "setBackgroundColor",
        android.R.color.transparent);
    

    or

    remoteView.setInt(R.id.yourFrame,"setBackgroundColor",
        android.graphics.Color.TRANSPARENT);
    

    Also you can set background transparent of any layout or any view or any component by adding this code in XML:

    android:background="@android:color/transparent"