Below code makes the Title bar to go red and Roboto-Regular font, code work properly but when orientation changes then Title will go to default properties, White color and default font. if i remove config changes in "activity" of manifest then onCreate would be called and font would be Red even after orientation change but i need to have config changes listener.
@Override
protected void onCreate(Bundle savedInstanceState) {
....
Typeface Roboto_Regular = Typeface.createFromAsset(getAssets(),"fonts/Roboto-Regular.ttf");
int titleId = getResources().getIdentifier("action_bar_title", "id","android");
TextView title = (TextView) findViewById(titleId);
title.setTypeface(Roboto_Regular);
title.setTextColor(getResources().getColor(android.R.color.holo_red_dark));
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Typeface Roboto_Regular = Typeface.createFromAsset(getAssets(),"fonts/Roboto-Regular.ttf");
int titleId = getResources().getIdentifier("action_bar_title", "id","android");
TextView menuTitle = (TextView) findViewById(titleId);
menuTitle.setTypeface(Roboto_Regular);
menuTitle.setTextColor(getResources().getColor(android.R.color.holo_red_dark));
invalidateOptionsMenu();
}
And in manifest
<activity
android:name="com.example.fontexperiment.MainActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" >
------------- updated with more info
if we read above link, it can be found that android:id="@+id/action_bar_title"
is what android has in layout file for title.
I checked in layout-land, there is not separate layout used for case of landscape. So the id of action bar title is same.
in my code i do get a null exception when i do
getResources().getIdentifier("action_bar_title", "id","android")
so the action bar title is proper, but the effect is not happening.
Does onConfigurationChanged() gets called after at end or very beginning? if at beginning then android might be setting title to defaults.