Search code examples
androidcolorsandroid-actionbarxamarintitlebar

Change the text color of the activity title


In Xamarin, how can I change the text colour of the text in the ActionBar?

I have changed the background colour successfully, but not the text colour.

Here is my code:

ColorDrawable colorDrawable = new ColorDrawable(Color.White);
ActionBar.SetBackgroundDrawable(colorDrawable); 
this.TitleColor = Color.Black;

I cannot see a correct method in the ActionBar object, and specifying this.TitleColor does not work correctly.


Solution

  • did you try this?

    int actionBarTitleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
    if (actionBarTitleId > 0) {
        TextView title = (TextView) findViewById(actionBarTitleId);
        if (title != null) {
            title.setTextColor(Color.RED);
        }
    }
    

    more info on this Site