How to Change Text Color of Toolbar Title in an Android App?
In an Android app, the toolbar title present at the upper part of the application. Below is a sample image that shows you where the toolbar title is present.
In the above image, you may see that the color of the Toolbar Title is white which is by default. So in this article, you will learn how to change the text color of the Toolbar Title in an Android App. There are two ways to change the color of the Toolbar Title.
Method 1: By Adding Child TextView in the activity_main.xml file
In method 1 Just go to the activity_main.xml file and add a TextView in the toolbar widget with the text color attribute. The complete code for the activity_main.xml file is given below.
Method 2: By Setting TextColor Programmatically
Step 1: Working with the activity_main.xml file
Go to the activity_main.xml file and refer to the following code. Below is the code for the activity_main.xml file.
Step 2: Changes in the themes.xml file
Go to the app > res > values > themes > themes.xml file and add the following line inside the <resources> tag.
Step 3: Working with the MainActivity file
In the activity’s onCreate() method, call the activity’s setSupportActionBar() method, and pass the activity’s toolbar. This method sets the toolbar as the app bar for the activity. Add below codes in your Activity to set the text color to the Toolbar title. Below is the complete code for the MainActivity.java / MainActivity.kt file.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.