ActionBar text color

后端 未结 24 3029
日久生厌
日久生厌 2020-11-22 05:31

how can I change the text color of the ActionBar? I\'ve inherited the Holo Light Theme, I\'m able to change the background of the ActionBar but I don\'t find out what is the

24条回答
  •  清歌不尽
    2020-11-22 06:20

    I found a way that works well with any flavor of ActionBar (Sherlock, Compat, and Native):

    Just use html to set the title, and specify the text color. For example, to set the ActionBar text color to red, simply do this:

    getActionBar()/* or getSupportActionBar() */.setTitle(Html.fromHtml("" + getString(R.string.app_name) + ""));
    

    You can also use the red hex code #FF0000 instead of the word red. If you are having trouble with this, see Android Html.fromHtml(String) doesn't work for text.


    Additionally, if you want to use a color resource, this code can be used to get the correct HEX String, and removing the alpha if needed (the font tag does not support alpha):

    int orange = getResources().getColor(R.color.orange);
    String htmlColor = String.format(Locale.US, "#%06X", (0xFFFFFF & Color.argb(0, Color.red(orange), Color.green(orange), Color.blue(orange))));
    

提交回复
热议问题