How to change action bar title color in code

前端 未结 6 1277
陌清茗
陌清茗 2020-11-27 05:28

I\'m having trouble changing androids action bar title color programmatically for v11 and up. I can get it done in xml but need to change it dynamically in code. How should

6条回答
  •  萌比男神i
    2020-11-27 06:15

    You can use a SpannableString and ForegroundColorSpan to set the colour of the title

        Spannable text = new SpannableString(actionBar.getTitle());
        text.setSpan(new ForegroundColorSpan(Color.BLUE), 0, text.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        actionBar.setTitle(text);
    

提交回复
热议问题