简体   繁体   中英

Android contact view style

Android contact view

I have a database with a column called PoemTitle , so I want to get the first letter from each title and give it a vector background with different colors. Please, can anyone help me with a function to do so depending on the char type? Below is the code that I tried:

fun getHeaderFirstChar(poems:Poems, res: Resources) {
  when (poems.PoemTitle.first()) {
    'a'..'b' -> res.getbackground
  }
}

That is the code I tried but it's not working Note: language is Kotlin and I'm using RoomDatabase

Don't re-invent the wheel, have a look at this library: https://github.com/amulyakhare/TextDrawable 在此处输入图片说明

and yes its Java but you can use it in Kotlin as well!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM