herbertD
herbertD

Reputation: 10955

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.

Upvotes: 1

Views: 3917

Answers (4)

albertkhang
albertkhang

Reputation: 701

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.

Upvotes: 0

vijay
vijay

Reputation: 1495

 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

Upvotes: 2

Sunil Parmar
Sunil Parmar

Reputation: 1233

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

remoteView.setInt(R.id.imgViewFollowed, "setBackgroundResource", R.drawable.icon_followed);

Upvotes: 3

Overrided
Overrided

Reputation: 157

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"

Upvotes: 2

Related Questions