I want to change the default typeface of the items of the overflow menu and set a custom typeface.
I tried adding a Factory to the LayoutInflater
and within the onCreateView()
method I changed the TextView's typeface. But it didn't work. Here is the code(Inside onCreateOptionsMenu),
getLayoutInflater().cloneInContext(this).setFactory(new LayoutInflater.Factory() {
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
if (name.contains("com.android.internal.view.menu.IconMenuItemView")) {
try {
LayoutInflater li = LayoutInflater.from(context);
final View view = li.createView(name, null, attrs);
new Handler().post(new Runnable() {
@Override
public void run() {
((TextView) view).setTypeface("custom_typeface");
}
});
return view;
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
});
Actually when I debug the code, it never reached inside onCreateView().
So how to fix this?
Thanks.