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

1

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.

android
background
imageview
remoteview
asked on Stack Overflow Jan 4, 2013 by herbertD • edited Jan 7, 2013 by herbertD

4 Answers

3

You can also use following to set background of ImageView for remoteview

remoteView.setInt(R.id.imgViewFollowed, "setBackgroundResource", R.drawable.icon_followed);
answered on Stack Overflow Jun 24, 2013 by Sunil Parmar
2

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"
answered on Stack Overflow Jan 4, 2013 by Overrided • edited Jan 4, 2013 by akjoshi
1
 RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.activity_main);

views.setInt(R.id.image1, "setBackgroundResource", android.R.color.holo_blue_bright);

its working fine for me

answered on Stack Overflow Mar 30, 2015 by vijay
0

First, you need to change the colours of your view by

remoteview.setInt(R.id.viewId, "setBackgroundColor", color)

Then you update the change to your RemoteViews by

val notificationManager: NotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(ID.SERVICE_ID, notification)

Hope that help you.

answered on Stack Overflow Mar 4, 2020 by Albert Khang

User contributions licensed under CC BY-SA 3.0