Set custom font for menu items in Android -
i tried implement custom menu. used answer given in this question. in code name expandedmenuitem, in examples iconmenuitemview. happening there? how can correct this?
here code.
public class myactivity extends preferenceactivity { @override public boolean oncreateoptionsmenu(menu menu) { menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.proximity_alert_menu, menu); getlayoutinflater().setfactory(new factory() { @override public view oncreateview(string name, context context, attributeset attrs) { //if(name.equalsignorecase("com.android.internal.view.menu.menuitem")) {} try { layoutinflater li = layoutinflater.from(context); final view view = li.createview(name, null, attrs); new handler().post(new runnable() { public void run() { textview tview = (textview) view; tview.settypeface(config.set_font); tview.settextcolor(color.red); } }); return view; } catch (inflateexception e) { e.printstacktrace(); } catch (classnotfoundexception e) { e.printstacktrace(); } return null; } }); return super.oncreateoptionsmenu(menu); } }
exception show that
java.lang.classcastexception:com.android.internal.view.menu.expandedmenuview cannot cast android.widget.textview
how can cast textview?
you can check follows view
textview
or not...
if (view instanceof textview) { textview tview = (textview) view; tview.settypeface(config.set_font); tview.settextcolor(color.red); }
if view textview
font
, color
changed.
Comments
Post a Comment