在android中使用自定义类型面创建自定义通知

在android中使用自定义类型面创建自定义通知,android,android-notifications,android-custom-view,Android,Android Notifications,Android Custom View,您好,我看到一些应用程序创建并显示带有自定义字体的自定义通知,我在谷歌上搜索,找到了。 但这对我不起作用这是我的代码 public static void CustomNotificationV(Context context, String message,boolean enter) { SpannableStringBuilder sb = new SpannableStringBuilder(mess

您好,我看到一些应用程序创建并显示带有自定义字体的自定义通知,我在谷歌上搜索,找到了。
但这对我不起作用这是我的代码

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 so it does not start a 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);
}
还有我的CustomTypefaceSpan类

package tools;

import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.text.style.TypefaceSpan;

/**
 * Created by 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);
}
}
但当我使用这段代码时,什么也不会发生,通知显示为defualt字体。

有人能帮我吗?

我想你应该用另一种方式来显示你的自定义文本,我发现这篇文章检查一下,希望你会发现这很有用。虽然它正在创建位图,但您可以进行自定义

您是否设置了要显示的字体。您应该在Assets中包含.ttf文件,并将其作为字符串传递到customTypefaceSpan类Yes中的这一行“sb.setSpan(新customTypefaceSpan(“,Constants.molla)”,0,sb.length()-1,SPAN.SPAN(独占的);”Constants.molla是我的字体Face我想你也需要在字符串族中传递一些东西看看这个我看到了,但是在那篇文章中没有为字体族设置任何东西你能说一下我必须为字体族设置什么吗?