LoginSignup
2
0

More than 5 years have passed since last update.

Notificationのタイトルに色を付ける方法

Last updated at Posted at 2019-02-25

こったプッシュ通知(notification)だと色付きのものをよく見るがそれをする方法
意外と調べても出てこなかったので掲載

addColorMethod.kt
private fun addColor(title: String): SpannableString {
    return SpannableString(title).apply {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            return@apply
        }
        setSpan(ForegroundColorSpan(ContextCompat.getColor(context,
                R.color.notification_job_title_text)), 0, title.length, 0)
    }
}
NotificationCompatBuilderでの利用法.kt
NotificationCompat.Builder(yourContext, "yourId")
    .setContentTitle(addColor("your notification title"))
    .set .. // 中略
    .build()

現場からは以上です

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0