Programatically apply various styles.xml to android supportActionBar

53 Views Asked by At

Me again,

I'm trying to programtically set the supportActionBar style/theme so I can achieve the below:

enter image description here

NB the title text has been made smaller and the subtitle text bigger.

It works perfectly when I set it via the styles.xml, however, I do not want to change this sytem wide, when I have no subtitle in my supportActionBar I would like the style/theme to go back to the original style/theme (text size) my app would use by default.

Any help would be appreciated. I have tried the below to no avail:

fun setActionBarSubtitle(subtitle: String) {
    if (subtitle.isEmpty() || subtitle.isBlank()) {
        // apply the default styling
        //(activity as AppCompatActivity)!!.supportActionBar!!.themedContext.setTheme(android.R.style.ThemeOverlay_Material_ActionBar)
    } else {
        // apply my custom styling
        //(activity as AppCompatActivity?)!!.supportActionBar!!.themedContext.setTheme(R.style.AppTheme_Styled_ActionBar)
    }

    (activity as AppCompatActivity)!!.supportActionBar!!.subtitle = subtitle
}
0

There are 0 best solutions below