Im trying to change the font of my menu items to a custom font. In my action bar is a dropdown menu with a couple of options. When I pick one the these options, the title of the item in the actionbar changes to this optiontext and it will apply the font. This is because I applied te font in the overrided 'onOptionItemSelected(MenuItem item)'. I really want the font to be applied when the menu gets created (it uses the default font right now). So I attempted to do this in the 'onCreateOptionsMenu(Menu menu)', but it keeps giving me an error (null pointer exception). I even tried multiple overrided methods, but nothing seems to work. How can I get my custom font applied to the menu item when it's been created? Here is my code:
@Override
public boolean onCreateOptionsMenu(Menu menu){
Log.d("GraphActivity", "onCreateOptionsMenu");
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_graph, menu);
optionMenu = menu;
Boolean dayMatch = User.getInstance().getDownloadedDay() == User.getInstance().getCurrentDay();
Boolean monthMatch = User.getInstance().getDownloadedMonth() == User.getInstance().getCurrentMonth();
Boolean yearMatch = User.getInstance().getDownloadedYear() == User.getInstance().getCurrentYear();
if(! dayMatch || ! monthMatch || ! yearMatch){
FeedbackManager feedbackManager = new FeedbackManager();
feedbackManager.showToast("file is out of date", GraphActivity.this, Toast.LENGTH_SHORT);
optionMenu.findItem(R.id.action_refresh).setIcon(R.drawable.ic_action_refreshed);
}
return true;
}
@Override
public boolean onMenuOpened(int featureId, Menu menu){
Typeface typeface = Typeface.createFromAsset(getAssets(), "TitilliumWeb-Regular.ttf");
menuItemView = (TextView)findViewById(R.id.action_select);
menuItemView.setTypeface(typeface);
return super.onMenuOpened(featureId, menu);
}
@Override
public boolean onCreatePanelMenu(int featureId, Menu menu)
{
Typeface typeface = Typeface.createFromAsset(getAssets(), "TitilliumWeb-Regular.ttf");
menuItemView = (TextView)findViewById(R.id.action_select);
menuItemView.setTypeface(typeface);
return super.onCreatePanelMenu(featureId, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
Log.d("GraphActivity", "onOptionsItemSelected");
Typeface typeface = Typeface.createFromAsset(getAssets(), "TitilliumWeb-Regular.ttf");
menuItemView = (TextView)findViewById(R.id.action_select);
menuItemView.setTypeface(typeface);
int id = item.getItemId();
if(id == R.id.action_settings){
Intent intent = new Intent(GraphActivity.this, SettingsActivity.class);
startActivity(intent);
}else if(id == R.id.action_refresh){
if(itemClickable){
TaskManager taskManager = new TaskManager(GraphActivity.this, progressBar);
taskManager.runTask("online");
}
}else if(id == R.id.action_current){
graphManager.setSelect(GraphManager.select_current);
String title = optionMenu.findItem(R.id.action_current).getTitle().toString();
optionMenu.findItem(R.id.action_select).setTitle(title);
setSelectable(WEEK_button);
setSelectable(MONTH_button);
setClickable(YEAR_button);
graph();
}else if(id == R.id.action_previous){
graphManager.setSelect(GraphManager.select_previous);
String title = optionMenu.findItem(R.id.action_previous).getTitle().toString();
optionMenu.findItem(R.id.action_select).setTitle(title);
setSelectable(WEEK_button);
setSelectable(MONTH_button);
setClickable(YEAR_button);
graph();
}else if(id == R.id.action_compare){
graphManager.setSelect(GraphManager.select_compare);
graphManager.setPeriod(GraphManager.period_year);
String title = optionMenu.findItem(R.id.action_compare).getTitle().toString();
optionMenu.findItem(R.id.action_select).setTitle(title);
setNonSelectable(WEEK_button);
setNonSelectable(MONTH_button);
setHighLight(YEAR_button);
setNotClickable(YEAR_button);
graph();
}
return super.onOptionsItemSelected(item);
}