Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 5+ custom notification XML layout with RemoteViews, set correct icon tint for ImageButton

My app is using a custom Notification layout with RemoteViews.

To display text, the layout is using the following system styles:

android:TextAppearance.Material.Notification.Title android:TextAppearance.Material.Notification

This works fine.

However, the TextAppearance style can't be used to set the value of android:tint, so I had to hardcode the color.

To my best knowledge, there's no special system style for setting notification ImageButton tint.

Hardcoded colors work fine on the current Android 5+ systems, but some users install custom ROMs with custom dark themes, and the notification looks wrong, i.e. black icons on black background.

Is there any way to get the system notification icon / imagebutton color, and apply it from an XML layout?

Or maybe there's another way to achieve this?

like image 936
Alexey Yakovenko Avatar asked Jan 09 '17 09:01

Alexey Yakovenko


People also ask

What is RemoteViews?

android.widget.RemoteViews. A class that describes a view hierarchy that can be displayed in another process. The hierarchy is inflated from a layout resource file, and this class provides some basic operations for modifying the content of the inflated hierarchy.

What is a custom app notification?

Custom Notifications option lets you select tones, vibration length, light, popup notifications, call ringtone, among others.


3 Answers

Sorry, But as per my knowledge custom ROM's have separate system designs,configurations and that are not official as well.

So,supporting Custom ROM without knowledge about its design is not possible. And android APIs are for supporting official ROM's.

Hope it Helps!!

like image 185
Animesh Mangla Avatar answered Oct 22 '22 07:10

Animesh Mangla


Try this example :

Definition for notification :

// Declare variable
public static Bitmap icon;

// Assign value but this line can be different depends on current 
// android sdk vesion ...
icon = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.YOUR_IMAGE);

     mBuilder = new NotificationCompat.Builder(this);
     mBuilder.setShowWhen(false);
     mBuilder.setDefaults(Notification.DEFAULT_ALL);
     mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
     mBuilder.setSmallIcon(R.drawable.image1); // One way to load img
     mBuilder.setContentText("this text not visible");
     mBuilder.setLargeIcon(icon);// This is the line
     mBuilder.setPriority(Notification.PRIORITY_DEFAULT);
     mBuilder.setContent(contentNotifySmall); // ORI
     //mBuilder.setAutoCancel(false);
     mBuilder.setCustomBigContentView(contentNotify);

I setup small and big variant for any case , this is important.

like image 31
Nikola Lukic Avatar answered Oct 22 '22 09:10

Nikola Lukic


for background can you try these attributes...

app:backgroundTint="@color/pay"

---------Or-------------

android:tint="@color/white"
like image 1
kiturk3 Avatar answered Oct 22 '22 08:10

kiturk3