Reputation: 6606
I am attempting to style the ActionBarCompat title text, I was not able to find any native ActionBarCompat methods to do the three things I needed to do which were change the text color to white, add some padding to the bottom of the text, and change the text typeface, after some googling I was able to find a method that did this by referencing the title textview by id like this and applying the changes as normal
int titleId = Resources.getSystem().getIdentifier("action_bar_title",
"id", "android");
actionBarText = (TextView) findViewById(titleId);
actionBarText.setPadding(0, 0, 0, 10);
actionBarText.setTypeface(textStyleThin);
actionBarText.setTextSize(20);
However the problem that I have is when the device rotates the screen and changes the orientation the title text resets to its default black color, original padding and regular typeface, whats even worse is it appears that the changes I had made can only be done in the OnCreate method and when I try to set it back the way I want in code it will not work the second time for some reason, does anyone know a way I can make the chages I need and keep it permanent or at the very least reset it if needs be? any help will go a long way, thanks
Upvotes: 1
Views: 431
Reputation: 6606
Just figured it out, the reason that i was not able to set the styles a second time was because I assumed that because the variable I created for the textview was global that I didnt need to reference the view by id again like it normally works, however by adding
int titleId = Resources.getSystem().getIdentifier("action_bar_title",
"id", "android");
actionBarText = (TextView) findViewById(titleId);
before calling
actionBarText.setPadding(0, 0, 0, 10);
actionBarText.setTypeface(textStyleThin);
actionBarText.setTextSize(20);
again it will work repeated times, I am sure this will help someone else in the future
Upvotes: 1