When I create an Options Menu the items seem to default to the native "sans" font. When I look at commercial apps they mostly seem to do the same thing. Is it possible to set the font size, color weight or typeface for Option Menu items?
Thanks in advance.
Click on the page menu in the top right-hand corner. It's the three horizontal dots. You'll see three options: Default, Serif, and Mono. Just pick the one you like best, and the font will automatically change.
Go to Format > Font > Font. + D to open the Font dialog box. Select the font and size you want to use. Select Default, and then select Yes.
The font options can all be found in the Home tab on the left. Older versions of Word may have font options in the top-left corner or in the Format menu. If you have an older version of Word, search the internet for where to find the font options in your specific version.
To change the font:On the Home tab, click the drop-down arrow next to the Font box. A menu of font styles will appear. Select the font style you want to use. The font will change in the document.
You can customize the option menu, including:
Add a custom font
Change font size
Change font color
Set background to a Drawable resource (e.g. image, border, gradient)
To change background to a border or gradient you have to create a resource folder in res
called drawable
and, inside it, create the border XML or gradient XML.
This can all be done programatically as shown below:
public class CustomMenu extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } public boolean onCreateOptionsMenu(android.view.Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.cool_menu, menu); getLayoutInflater().setFactory(new Factory() { public View onCreateView(String name, Context context, AttributeSet attrs) { if (name.equalsIgnoreCase( "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() { public void run() { // set the background drawable if you want that //or keep it default -- either an image, border //gradient, drawable, etc. view.setBackgroundResource(R.drawable.myimage); ((TextView) view).setTextSize(20); // set the text color Typeface face = Typeface.createFromAsset( getAssets(),"OldeEnglish.ttf"); ((TextView) view).setTypeface(face); ((TextView) view).setTextColor(Color.RED); } }); return view; } catch (InflateException e) { //Handle any inflation exception here } catch (ClassNotFoundException e) { //Handle any ClassNotFoundException here } } return null; } }); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.AboutUs: Intent i = new Intent("com.test.demo.ABOUT"); startActivity(i); break; case R.id.preferences: Intent p = new Intent("com.test.demo.PREFS"); startActivity(p); break; case R.id.exit: finish(); break; } return false; } }
Dont forget to create folder called menu
in res
folder, and inside the menu
folder create an XML for your menu (e.g. cool_menu.xml) such as this:
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:title="about"android:id="@+id/AboutUs" /> <item android:title="Prefs" android:id="@+id/preferences" /> <item android:title="Exit" android:id="@+id/exit" /> </menu>
Then the output will be something like this:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With