Create custom notification with custom type face in android -
hi see app create , show custom notification custom typeface , googling , found this question.
not work me code
public static void customnotificationv(context context, string message,boolean enter) { spannablestringbuilder sb = new spannablestringbuilder(message); sb.setspan(new customtypefacespan("", constants.molla), 0, sb.length() - 1, spanned.span_exclusive_inclusive); int icon=r.drawable.ex; // create new id date date = new date(); int notificationid = (int) date.gettime(); long when = system.currenttimemillis(); notificationmanager notificationmanager = (notificationmanager) context .getsystemservice(context.notification_service); notification notification = new notification(icon, message, when); intent notificationintent = new intent(context, splash.class); // set intent not start new activity notificationintent.setflags(intent.flag_activity_clear_top | intent.flag_activity_single_top); pendingintent intent = pendingintent.getactivity(context, notificationid, notificationintent, 0); remoteviews contentview = new remoteviews(context .getapplicationcontext().getpackagename(), r.layout.custom_notification); contentview.setimageviewresource(r.id.leftimage, icon); contentview.settextviewtext(r.id.message_custom_notification, sb); notification.contentview = contentview; notification.contentintent = intent; notification.flags |= notification.flag_auto_cancel; notificationmanager.notify(notificationid, notification); }
and customtypefacespan class
package tools; import android.graphics.paint; import android.graphics.typeface; import android.text.textpaint; import android.text.style.typefacespan; /** * created mk-rad on 08/02/2015. */ public class customtypefacespan extends typefacespan { private final typeface newtype; public customtypefacespan(string family, typeface type) { super(family); newtype = type; } @override public void updatedrawstate(textpaint ds) { applycustomtypeface(ds, newtype); } @override public void updatemeasurestate(textpaint paint) { applycustomtypeface(paint, newtype); } private static void applycustomtypeface(paint paint, typeface tf) { int oldstyle; typeface old = paint.gettypeface(); if (old == null) { oldstyle = 0; } else { oldstyle = old.getstyle(); } int fake = oldstyle & ~tf.getstyle(); if ((fake & typeface.bold) != 0) { paint.setfakeboldtext(true); } if ((fake & typeface.italic) != 0) { paint.settextskewx(-0.25f); } paint.settypeface(tf); } }
but when use code nothing happens , notification shows defualt typeface.
can me this?
i think should alternate way of displaying custom text, have found post https://stackoverflow.com/a/4411060/1007087 check , hope might find useful. though creating bitmap can customization.
Comments
Post a Comment